Note The migration process is currently manual.
Service Catalogue uses the Prisma ORM for database migrations, to profit from the audit trail it provides.
Migrations are located in ../packages/common/prisma/migrations.
Prisma tracks the migration history in the _prisma_migrations
table in the database.
See https://www.prisma.io/docs/guides/migrate/developing-with-prisma-migrate#create-migrations for the recommended process for developing a migration.
To create a migration file, run:
npx -w common prisma migrate dev --create-only --name [name]
Once you have a draft migration, apply it via:
npm -w cli start migrate -- --stage DEV
You can then generate a new version of the Prisma Client via:
npx -w common prisma generate
Upon a RiffRaff deploy (to either CODE or PROD), a prisma.zip
containing the Prisma schema and migration scripts is uploaded into the account artifact bucket. This action triggers an ECS task running the prisma-migrate
container, which retrieves the prisma.zip
and applies the corresponding migration to the CODE/PROD RDS instance.
This migrations can fail for a number of reasons - for example attempting to add a NOT NULL
column to a table with existing data. In this case, manual intervention will be necessary. Prisma provides some useful documentation on patching and hotfixing.
Although migrations are applied automatically on deploy, these documentation is preserved here in case a manual migration is necessary.
Prerequisite:
- You have an approved Pull Request
- You have
deployTools
credentials from Janus - You are connected to the VPN
You can apply a migration to CODE or PROD using the CLI):
npm -w cli start migrate -- --stage [CODE|PROD]
The command above will not apply the migration without a --confirm
flag. If satisfied with the output of the above, you can run:
npm -w cli start migrate -- --stage [CODE|PROD] --confirm
See also: