Skip to content

Instantly share code, notes, and snippets.

@kirlf
Last active May 25, 2021 13:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kirlf/219979e4ff90494e81ee49d314b8e54c to your computer and use it in GitHub Desktop.
Save kirlf/219979e4ff90494e81ee49d314b8e54c to your computer and use it in GitHub Desktop.
LOAD DATABASE
FROM mysql://user:password@mysql57:3306/mysql_db
INTO postgresql://user:password@pgsql:5432/pg_db
CAST type int with extra auto_increment when (< precision 10) to serial drop typemod drop not null,
type int with extra auto_increment when (<= 10 precision) to bigserial drop typemod drop not null,
type int when (< precision 10) to int drop typemod,
type int when (<= 10 precision) to bigint drop typemod,
type tinyint with extra auto_increment to serial drop not null,
type smallint with extra auto_increment to serial drop not null,
type mediumint with extra auto_increment to serial drop not null,
type bigint with extra auto_increment to bigserial drop not null,
type tinyint when (= 1 precision) to boolean drop typemod using tinyint-to-boolean,
type bit when (= 1 precision) to boolean drop typemod using bits-to-boolean,
type bit to bit drop typemod using bits-to-hex-bitstring,
type bigint when signed to bigint drop typemod,
type bigint when (< 19 precision) to numeric drop typemod,
type tinyint when unsigned to smallint drop typemod,
type smallint when unsigned to integer drop typemod,
type mediumint when unsigned to integer drop typemod,
type integer when unsigned to bigint drop typemod,
type tinyint to smallint drop typemod,
type smallint to smallint drop typemod,
type mediumint to integer drop typemod,
type integer to integer drop typemod,
type bigint to bigint drop typemod,
type float to float drop typemod,
type double to double drop typemod,
type numeric to numeric keep typemod,
type decimal to decimal keep typemod,
type char to char keep typemod using remove-null-characters,
type varchar to varchar keep typemod using remove-null-characters,
type tinytext to text using remove-null-characters,
type text to text using remove-null-characters,
type mediumtext to text using remove-null-characters,
type longtext to text using remove-null-characters,
type json to jsonb
;
version: '3.5'
services:
mysql57:
container_name: cloud-service-shop-mysql_test_57
image: mysql:5.7
restart: always
environment:
- MYSQL_DATABASE=mysql_db
- MYSQL_USER=user
- MYSQL_PASSWORD=password
- MYSQL_ALLOW_EMPTY_PASSWORD=true
entrypoint: [ '/entrypoint.sh', '--default-authentication-plugin=mysql_native_password' ]
ports:
- 3308:3306
pgsql:
image: postgres:13.2
restart: always
ports:
- 5433:5432
environment:
- POSTGRES_DB=pg_db
- POSTGRES_USER=user
- POSTGRES_PASSWORD=password
pgloader:
image: dimitri/pgloader:latest
volumes:
- ./pgload.load:/opt/pgload.load
command: ["pgloader", "/opt/pgload.load"]
# only tables schemas
docker-compose exec -T pgsql pg_dump -Uuser -w -s pg_db > pg_tables.sql
# including data
docker-compose exec -T pgsql pg_dump -Uuser -w --column-inserts pg_db > pg_dump.sql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment