Any pending migrations are done automatically during deployment as part of npm run build, more precisely they are run from web/bin/sync-db.js.
We also have a custom setup where, if the database is not initialized, we first:
  • just creates the database from the latest model descriptions
  • manually fill in the SequelizeMeta migration tracking table with all available migrations to tell Sequelize that all migrations have been done up to this point
This is something that should be merged into Sequelize itself, or at least asked on Stack Overflow, but lazy now.
In order to test migrations locally interactively, you can:
  • commit them on Git
  • git checkout HEAD~
  • reset the database with demo data:
    cd web
    ./bin/generate-demo-data.js --clear
  • Move back to master: git checkout -
  • Run the migration:
    ./bin/sync-db.js
This is usually done in a single command:
cd web &&
git add migrations &&
git commit -an &&
git checkout HEAD~ &&
./bin/generate-demo-data.js --clear &&
git checkout - &&
./bin/sync-db.js
For PostgreSQL:
cd web &&
git add migrations &&
git commit -an &&
git checkout HEAD~ &&
OURBIGBOOK_POSTGRES=true ./bin/generate-demo-data.js --clear &&
git checkout - &&
NODE_ENV=production OURBIGBOOK_POSTGRES=true ./bin/sync-db.js

Ancestors