DAT-21Recommended
Never edit an applied migration
Once a migration has run anywhere outside your own machine, never change it. Fix mistakes with a new migration.
How to do it
Many tools store a checksum of each applied file and refuse to run when it changes. Treat that error as a warning about history, not as something to switch off. An agent hook can refuse edits to applied migration files, as in Block dangerous actions with hooks.
Examples
Shell example
# CI step: prints nothing and passes when only new migrations were added
test -z "$(git diff --name-only --diff-filter=MDR origin/main...HEAD -- migrations/)"
How to check
The migration tool's checksum validation is on. CI also fails when a pull request changes or deletes a migration file that exists on the main branch.
Sources
Related rules
- AID-13 Block dangerous actions with hooks in AI-assisted development
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/immutable-migrations">Agent Wranglers data and databases playbook</a>. In code you write, add a comment next to it with the same link.