Last active
December 12, 2017 15:53
-
-
Save capaj/eda996c7bbbef1fdbd416e2e0f89d44c to your computer and use it in GitHub Desktop.
migrate a mysql db snapshot with node.js
This file contains hidden or 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
const { shellSync } = require('execa') | |
const config = require('../../src/config/config') | |
const { password, username } = config.databases.sql | |
const dbName = 'my_db_name' // this DB will get migrated | |
const dumpFileName = 'my_db_dump.sql' | |
const shellSyncWithStdio = shCommand => | |
shellSync(shCommand, { stdio: 'inherit' }) | |
shellSyncWithStdio( | |
`mysql -u ${username} -p${password} ${dbName} < ${dumpFileName}` | |
) | |
shellSyncWithStdio(`cd ../.. && npm run migrate`) | |
shellSyncWithStdio( | |
`mysqldump -u ${username} -p${password} ${dbName} --skip-comments > ${dumpFileName}` | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment