-
-
Save philsmy/8cfb57b9250edb350e7b7259280766cd to your computer and use it in GitHub Desktop.
The files needed for getting a rails app running with postgres and pulling in the data from your old mysql database. As per my video here: https://youtu.be/2SOfvPZJZoM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PORT=3000 | |
# postgresql | |
POSTGRES_HOST=localhost | |
POSTGRES_PORT=54323 | |
POSTGRES_DBUSER=postgres | |
POSTGRES_PASSWORD=philsmy123 | |
# mysql | |
MYSQL_DBNAME=lotteryportal_development | |
MYSQL_DBUSER=mysqluser | |
MYSQL_DBPASS=philsmy123 | |
MYSQL_DBPORT=13306 | |
TZ=Asia/Tokyo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# PostgreSQL. Versions 9.3 and up are supported. | |
# | |
# Install the pg driver: | |
# gem install pg | |
# On macOS with Homebrew: | |
# gem install pg -- --with-pg-config=/usr/local/bin/pg_config | |
# On macOS with MacPorts: | |
# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config | |
# On Windows: | |
# gem install pg | |
# Choose the win32 build. | |
# Install PostgreSQL and put its /bin directory on your path. | |
# | |
# Configure Using Gemfile | |
# gem "pg" | |
# | |
default: &default | |
adapter: postgresql | |
encoding: unicode | |
# For details on connection pooling, see Rails configuration guide | |
# https://guides.rubyonrails.org/configuring.html#database-pooling | |
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> | |
development: | |
<<: *default | |
host: <%= ENV['POSTGRES_HOST'] %> | |
port: <%= ENV['POSTGRES_PORT'] %> | |
username: <%= ENV['POSTGRES_USER'] %> | |
password: <%= ENV['POSTGRES_PASSWORD'] %> | |
database: lotteryportal_development | |
test: | |
<<: *default | |
host: <%= ENV['POSTGRES_HOST'] %> | |
port: <%= ENV['POSTGRES_PORT'] %> | |
username: <%= ENV['POSTGRES_USER'] %> | |
password: <%= ENV['POSTGRES_PASSWORD'] %> | |
database: lotteryportal_test | |
production: | |
<<: *default | |
url: <%= ENV['DATABASE_URL'] %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: "3.7" | |
services: | |
db: | |
image: postgres:13.5 | |
container_name: "lottery_postgres" | |
command: ["postgres", "-c", "logging_collector=on", "-c", "log_filename=postgresql.log", "-c", "log_statement=all"] | |
environment: | |
POSTGRES_PASSWORD: "${POSTGRES_PASSWORD}" | |
ports: | |
- 54323:5432 | |
volumes: | |
- lottery_dbdata:/var/lib/postgresql/data | |
# this is only here for the migration. Not needed for the actual service | |
mysqldb: | |
image: mysql:8.0 | |
volumes: | |
- mysqldb-store:/var/lib/mysql | |
- ./logs:/var/log/mysql | |
- ./docker/mysql/my.cnf:/etc/mysql/conf.d/my.cnf | |
environment: | |
- MYSQL_DATABASE=${MYSQL_DBNAME} | |
- MYSQL_USER=${MYSQL_DBUSER} | |
- MYSQL_PASSWORD=${MYSQL_DBPASS} | |
- MYSQL_ROOT_PASSWORD=${MYSQL_DBPASS} | |
- TZ=${TZ} | |
ports: | |
- ${MYSQL_DBPORT}:3306 | |
volumes: | |
lottery_dbdata: | |
mysqldb-store: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- See https://github.com/dimitri/pgloader/blob/master/pgloader.1.md for | |
-- connection string options. | |
LOAD DATABASE | |
FROM mysql://root:[email protected]:13306/lotteryportal_development | |
INTO postgresql://postgres:[email protected]:54323/lotteryportal_development | |
ALTER SCHEMA 'lotteryportal_development' RENAME TO 'public' | |
WITH data only, truncate, prefetch rows = 10000; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
docker pull dimitri/pgloader | |
docker run --rm --name pgloader dimitri/pgloader:latest pgloader --version | |
docker run --rm --name pgloader dimitri/pgloader:latest pgloader --help | |
docker run --rm --network host --name pgloader -v <your Rails root or wherever you have you command file>:/data dimitri/pgloader:latest pgloader --verbose /data/pgloader-commands |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment