Migration Rollback Recovery Runbook
Purpose
Recover whenmigrate:rollback fails mid-run and leaves a partial migration state.
Signals
- Non-zero rollback exit code
- Log line includes
Error rolling back ... - Mixed state in
migrate:status
Safety
- Backup before retrying rollback in production.
- Fix migrations in source, never in generated runtime artifacts.
- Avoid manual row-level edits in
migrationsunless unavoidable.
Single connection workflow
- Capture status:
-
Fix failing migration
down()implementation. - Re-run rollback for remaining migrations:
- Verify and re-apply:
All-connections workflow
migrate:status --all-connections(and--test)- Fix migration source
migrate:rollback --all-connections --all-migrations(and test)migrate:run --all-connections --all-migrations(and test)- re-check status
Post-incident checks
- Add or extend a regression test for the failing rollback pattern.
- Make
down()implementations idempotent. - Update release notes if behavior changes.
- Legacy
migration_lockstable can be cleaned up post-upgrade if desired:- SQLite/MySQL:
DROP TABLE IF EXISTS migration_locks; - PostgreSQL:
DROP TABLE IF EXISTS migration_locks CASCADE;
- SQLite/MySQL: