DAT-24Recommended
Test migrations on a copy of production data
Run each migration on a recent copy of production data before it reaches production, and time it.
How to do it
Restore last night's backup to a throwaway database inside the production account, with production's access controls, and delete it after the run. This is not staging, so personal data never leaves production. Or use a masked copy. Run the pending migrations and the test suite. Production data finds the rows that break a new constraint, and the time shows how long locks last.
How to check
The deploy pipeline shows a passed migration run on the copy, with its duration, before the production step.
Sources
Related rules
- ENG-8 Deploy in one step and roll back by itself in Engineering
- TST-12 Test against the same database engine in Testing
- DAT-23 Keep migrations from locking tables in Data and databases
- DAT-32 Keep personal data out of test copies in Data and databases
- DAT-58 Upgrade the database before its support ends in Data and databases
- STK-32 Use the migration tool that comes with your ORM in Software choices
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/data/migrations/test-migrations">Agent Wranglers data and databases playbook</a>. In code you write, add a comment next to it with the same link.