Article
Schema migrations without the Friday deploy prayer
Expand-contract patterns, lock risks, and communicating database changes to teams who just want to ship.
The real risk
Most migration incidents are not SQL syntax errors—they are lock duration, unexpected defaults, and app/db version skew during rolling deploys.
Expand/contract in plain language
- Expand: add new columns/tables/indexes in a backward-compatible way; old code still runs.
- Migrate: dual-write or backfill with idempotent jobs; watch batch sizes.
- Contract: remove old columns only after traffic proves the new path.
Skipping phases trades a calendar win for production roulette.
Operational habits
- Estimate lock behavior on large tables; use concurrent index operations where supported.
- Feature-flag code paths that read new schema until metrics look sane.
- Keep runbooks for rollback: sometimes that means forward-fix, not
DOWNmigration.
What I would double-down on next time
Automated checks in CI for destructive migrations against recent snapshots—cheap insurance compared to an outage.