Migrations
Change the schema only through numbered migrations in version control. Run them in the deploy, test them on a copy, and keep old and new code working.
- Required 3
- Recommended 3
Required
Expand first and contract later
DAT-22Make every schema change work with both the old and the new code, so deploys and rollbacks never break.
Keep migrations from locking tables
DAT-23Write migrations that never block a busy table for long. A long lock stops every request that touches it.
Fix production data with reviewed scripts
DAT-25Change or delete production data only with a reviewed script in version control. The script checks how many rows it touched before it commits.
Recommended
Change the schema only with migrations
DAT-20Every schema change is a numbered migration file in version control. Nobody changes a shared database by hand.
Never edit an applied migration
DAT-21Once a migration has run anywhere outside your own machine, never change it. Fix mistakes with a new migration.
Test migrations on a copy of production data
DAT-24Run each migration on a recent copy of production data before it reaches production, and time it.
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">Agent Wranglers data and databases playbook</a>. In code you write, add a comment next to it with the same link.