Skip to content

Instantly share code, notes, and snippets.

@capaj
Last active December 12, 2017 15:53
Show Gist options
  • Save capaj/eda996c7bbbef1fdbd416e2e0f89d44c to your computer and use it in GitHub Desktop.
Save capaj/eda996c7bbbef1fdbd416e2e0f89d44c to your computer and use it in GitHub Desktop.
migrate a mysql db snapshot with node.js
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