cli
cli copied to clipboard
Migrations / Seeds Production Ready?
I have a rather subjective question regarding Sequelize Cli that I wager others would also like perspectives on.
"Is Sequelize Cli Migrations/Seeds production pipeline ready?"
I have this in my CI/CD pipelines for DEV, STAGE and PROD which get run anytime the application/Docker container get restarted.
sequelize db:migrate &&
sequelize db:seed:all &&
yarn install &&
yarn start
We currently use this for 2 things:
- Commit seed files into the project that when run on a brand new startup will populate the DB with dummy data.
- Commit migration files into the project that essentially give us DB version control and allow us to perform changes to schema when the application is restarted. This would even apply to the live production DB "if restarted", however we would have these scripts run as part of a separate live db update pipe.
Just curious if this is the intended usage for Migrations/seeds. I've never managed this type of DevOps and wonder if it might be a potential hazard to rely on those seed and migration db tables to prevent these scripts from say dropping live table data. Thoughts?
db:seed:all doesn't appear to work when run multiple times.
For migrations, a row is inserted into SequelizeMeta by the name of the file that was run, and subsequent runs will check this table and not run migrations if they've already run.
Seeds don't appear to do this so you'll (likely) hit unique constraint errors.
Err....scratch that, by default, seed uses none for it's storage mechanism, so db:seed:all will attempt to run all them every time. You can configure migrations/seeds to use different storage mechanisms.
This can be done in sequelize config:
seederStorage: "none" || "sequelize" || "json"
see: https://github.com/sequelize/cli#seed
Sorry to hijack this Issue, but I can't see why seederStorage defaults to "none".
The docs also show a warning-like exclamation mark, without adding anything else, which is not obvious for me:
By default the CLI will not save any seed that is executed. If you choose to change this behavior (!), you can use seederStorage [...]
I usually run seeds by name one by one. I feel this is tedious for big releases. Just wanted to check if there is anything dangerous about going with sequelize seederStorage
Thanks!
Is that repository inactive or something ?
looks like
use seederStorage:sequelize and a table name for seederStorageTableName and you're good it was defined in the docs