Author: Harry Nguyen
Use MySQLWorkbench
to connect to prod DB.
Click menu Sever > Data Export
Select the DB and tables, choose Dump Structure Only
Selection option Export to selft-contained file
and change the name of exported file (eg: schema-backup.sql
)
Repeat step 1 to step 4 but at step 3 choose Dump Data Only
and change the name of exported file (eg: data-backup.sql
)
Use MySQLWorkbench
to create a new local DB.
Run schema-backup.sql
and data-backup.sql
to the newly created local DB to make it as same state as prod DB.
Install flyway
if it’s not installed.
Clone this repo and follow the README.md
file https://github.com/haintwork/flyway-db-migration-starter-kit, but stop before step 7 in README.md
file.
Comment the migrate
command in migrate-db-local.sh
script, uncomment the baseline
command.
Copy content of schema-backup.sql
and replace to V1__Init_DB.sql
file.
Run step 7 of README.md
file and check the local DB has new table flyway_schema_history
and column success value 1.
Create new sql file V1_0_1__Init_test.sql
in sql
folder of the code with content
CREATE TABLE test (
id serial PRIMARY KEY,
text VARCHAR ( 50 ) UNIQUE NOT NULL
);
Open script file migrate-db-local.sh
and comment baseline
command and uncomment migrate
command
Run /bin/bash/migrate-db-local.sh
and check if new test
table is created in local DB, if yes then it’s fine now.
Clone file migrate-db-local.sh
to migrate-db-prod.sh
and update prod db info in the script.
Uncomment the baseline
and comment migrate
Run /bin/bash/migrate-db-prod.sh
and check if table flyway_schema_history
is created in prod db.