-
-
Notifications
You must be signed in to change notification settings - Fork 57
Database Migrations
June Zhao edited this page Jan 11, 2024
·
4 revisions
Changes to database are run with the migration package
node-pg-migrate
node-pg-migrate uses the connection parameters set in
./server/db/config.js, which are sourced from the .env in the server folder
of the repo. See .env.sample for example of this.
To generate a new migration template called "add-books-table.js" run:
npm run migrate create add-books-tablefrom the server folder. This will output a migration file called <timestamp>-add-books-table.js in the migrations directory that can be filled out with the create table definition.
Read node-pg-migrate
docs for helpful
examples.
Once the migration script is ready apply it to the db with:
npm run migrate upTo roll back a migration run:
npm run migrate downand that will roll back the last migration.