-
There are two methods to initially setup the database schema: using
sequelize-cli
and usingsequelize.sync()
. -
During development of a feature
sequelize.sync()
can be used to alter the schema to follow along with the models/entities/dto changes. -
All stages after development, however, alerting the schema should be accomplished with
sequelize-cli
. -
It's easy for the
sequelize-cli
and usingsequelize.sync()
schemas to be out of sync. In order to reconcile the differences,create two databases using the two methods. ThenpgAdmin > Schema Diff
the resulting schemas, and then adjust either the nestjst-sequelize models or adjust the migration scripts until they both result in the same schema. -
No model/entity/dto changes should be meged into main without also adjusting for migration changes.
- used during migrations and deploys
- use at all stages of development
- create
migrations/.env
file with environment variables below
$ npm install
$ npx sequelize-cli db:migrate
- Simply starting the nestjs-sequelize app will run
sequelize.sync()
, and this will automagically update the database schema - convenient in development while building out backend models
- use only at local stages of development
- follow steps for running nestjs-sequelize app, while adding the following environment variable
$ SEQUELIZE_RUN_SYNC=true
DATABASE_HOST=
DATABASE_PORT=
DATABASE_USERNAME=
DATABASE_PASSWORD=
DATABASE_NAME=