Database changes are among the riskiest changes in software. A schema change that looked harmless in testing can lock a busy table, break an older version of the application or, worst of all, lose data. Many teams respond by bundling database changes into rare, scheduled maintenance windows, which makes each change bigger and riskier still.
There is a better way: make every database change small and backward compatible, so it can be deployed at any time while the application keeps running.
The core idea: expand, migrate, contract
Any breaking change can be broken into three non-breaking steps.
1. Expand
Add the new structure alongside the old one, without removing anything. For example, to rename a column, add the new column and leave the old one in place. Old application versions keep working because nothing they use has changed.
2. Migrate
Update the application to write to both old and new structures, then backfill existing data into the new structure in small batches. Once the new structure is complete and verified, switch reads to it.
3. Contract
When no application version uses the old structure any more, remove it. This is the only step that deletes anything, and by now nothing depends on it.
A worked example: renaming a column
| Step | Database | Application |
|---|---|---|
| Expand | Add customer_email next to email |
No change |
| Dual write | Both columns exist | Writes to both columns |
| Backfill | Copy existing values in batches | Still writes to both |
| Switch reads | Both columns exist | Reads customer_email |
| Contract | Drop email |
Uses only customer_email |
Each step is a separate, small, reversible deployment.
Practical rules
- Version every change. Schema changes live in version control as migration scripts and go through code review.
- Batch large updates. Backfill in small chunks to avoid long locks and replication lag.
- Know your engine’s locking behavior. Some operations that are instant on one database lock tables on another. Test with realistic data volumes.
- Keep a rollback path. Until the contract step, you can always go back.
- Verify data. Compare old and new structures with automated checks before switching reads.
- Back up first. A verified backup exists before any significant change.
Where AI helps
AI can help analyze query plans, find code that depends on a structure you plan to change, and draft migration and verification scripts. A database engineer reviews and tests every script before it runs, and AI tools work on schema and metadata, not on production data.
The payoff
Teams that adopt this pattern stop fearing database changes. Changes become routine, frequent and small, which in turn makes each one safer. The application evolves with the business instead of waiting for the next maintenance window.