Skip to content

Latest commit

 

History

History
70 lines (43 loc) · 2.56 KB

database-migrations.md

File metadata and controls

70 lines (43 loc) · 2.56 KB

Database Migrations

Note The migration process is currently manual.

What are they?

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.

Creating a new migration

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

Applying a migration to CODE or PROD

Migrations as part of CD

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.

Manual migrations

Although migrations are applied automatically on deploy, these documentation is preserved here in case a manual migration is necessary.

Prerequisite:

  1. You have an approved Pull Request
  2. You have deployTools credentials from Janus
  3. 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: