This Readme will shortly explain how to create database migrations for model changes introduced by a new branch (hereinafter referred to as "target branch").
It is necessary to have a local postgres database for development with the credentials stored in the corresponding environment variables when creating the migrations. This database is later used to store the state of the dev
branch which is then compared by TypeORM to the state on the target branch.
You'll need to perform the following steps to use TypeORM's auto generation feature for migrations:
- Make sure your branch is up-to-date with remote branch
dev
- Change your local branch to
dev
- Run command
npm run build:clean && npm run web:dev
. Your local db is now in the state defined by the current code on thedev
branch. - Change back to your target branch
- Generate a migration file with the command
npm run db:migration:generate NAME_OF_MIGRATION
where NAME_OF_MIGRATION is a simple and short description of what the new migration should do. - Check the generated file and delete unnecessary statements in up like
ALTER COLUMN "verification" SET DEFAULT null
and in down likeALTER COLUMN "verification" DROP DEFAULT
(please also see typeorm/typeorm#3076)
Comming soon...