As migrations affect production data, it is very important that you take all necessary measures so they work as expected.
This approach allows you to locally test your migration until you feel comfortable enough to run it on production.
If you have the required role to modify the database, migrations can be executed from your machine by running: integrates-db-migration prod name_of_script
.
Since our core linter also runs import-linter
, therefore, it will verify that forbidden modules are not being imported in migration scripts; this is done to avoid direct usage of modules that directly modify the database.
Unless strictly necessary, prefer using already existing utils in db_model; otherwise, add exception rules to your migration script.
If you require adding a rule exception, then modify the integrates/back/import-linter.cfg
config file.
Running on AWS Batch
Once you know that your migration does what it is supposed to do, it is recommended to execute it using a
Batch schedule:
- Write your migration.
- Create a batch schedule that executes the migration.
- Deploy both changes to production
- Wait until the schedule executes.
- Access the AWS console to review the logs of the migration.
This allows the migration to execute on an external environment from your own machine, which is faster and more reliable.
Restoring to a previous state
If something goes wrong, you have the option to restore data from a backup.
- Follow these instructions to restore a Point In Time into a new table.
- Restore the data by reading from the recovery table and writing into the main table
- Remove the recovery table
Delete migrations
Migrations should be kept in the repository for at least one year. After that, they should be deleted to avoid compatibility issues.
There is no need to delete a migration immediately after one year has passed (We have no test in the CI for that). The usual procedure is simply to delete them in bulk at least twice a year, once in January and another time in July.
Learn more
- Database design
- Data model
- Patterns
- Streams