General
We use the Knex library through the node-database library. See https://knexjs.org/guide/migrations.html for more
information on writing migrations.
Migrations that are always safe to perform
- Adding a new table
- Adding a nullable column
Migrations with breaking changes
Examples
- Dropping tables, procedures, or columns are always breaking.
- Renaming an existing table or column is always breaking.
- Adding a constraint MIGHT be breaking.
- Changing a columns data type MIGHT be breaking.
How to promote breaking changes to production
Migrations need to be compatible with the current production version of a service before they can be merged and deployed.
Ideas
- For dropping tables, columns, or adding constraints you should promote the new version of the service first, then
follow up with the database migration PR that modifies the database schema to be perfectly aligned with the new version.
- Merge & Deploy Service PR that removes DB references
- Merge & Deploy migration that removes the DB objects
- Avoid renaming tables and changing to more restrictive column data types. If this must be done it should be done in a maintenance window to minimize customer impact.
Migrations that may require out of band application
Any schema change that could take a very long time to complete should be applied out of band using a sql script. These would be created and added into banno-data-one-off-scripts. It’s important to understand the schema changes still need to exist in a migration, or you may become unable to recreate the database from the migrations.
- Create a sql script in banno-data-one-off-scripts that performs the long running schema change.
- Create a migration that performs the same schema change if it isn’t already applied.
Examples of long running migrations
- Adding an index to a very large table
- Adding a non nullable column to a very large table
- Adding a constraint to a very large table