Skill: database migration checklist
Encode expand/contract migration steps so agents never ship irreversible schema changes without a rollback path.
What to do first

Expand Contract
- Prefer expand → migrate → contract over one big-bang destructive PR.
- Never drop or rename a column still referenced by running code without a phased plan.
- Every migration needs rollback notes: or an explicit irreversible warning. Backfills are batched; no unbounded
UPDATEon huge tables.
Ask an agent to “rename user_name to full_name” and it often emits one migration that renames, updates the ORM, and deletes the old column in a single deploy. That works on an empty local DB and outages production. This skill forces expand/contract thinking: add safely, dual-write or backfill, switch reads, then remove: in separate PR boundaries when needed.
Trigger it for schema changes, index add/drop, data backfills, and ORM migration generation. Pair with incident first-hour if a bad migration is already live.
Part 1: Classify, then phase
Database migration planner. Do not invent production row counts.
Change request: [paste]
Classify: ADDITIVE | DESTRUCTIVE | DATA-ONLY
Then draft phases:
1. EXPAND: nullable columns, new tables, dual-write hooks
2. MIGRATE: batched backfill (batch size, idempotency, progress metric)
3. CONTRACT: switch reads, then drop old paths (separate PR unless user accepts downtime)
Include: rollback notes OR irreversible warning; lock/timeout risks on ALTER; monitoring (error rate, latency, lock waits).
Ask if table size is unknown: do not assume local emptiness means small.
Part 2: Phase gate before code

Phase Gate
Reject any single PR that:
- Renames/drops a column still read by running code
- Backfills an unbounded full-table UPDATE
- Omits rollback / irreversible callout
Emit PR boundaries: which files/migrations land in expand vs contract.
Save it as a skill file
# Skill: db-migration
## When
- Schema or data migrations
## Hard rules
1. Expand/contract unless user accepts downtime.
2. Batched backfills; no full-table locks by default.
3. Rollback notes or irreversible warning required.
4. Do not invent prod row counts.
## Steps
1. Classify change.
2. Expand / migrate / contract plan with PR boundaries.
3. Monitoring checklist.
4. Write migrations only after the plan is accepted.
## Done when
- Phased plan + rollback note exist.
Test before you trust it
- Drop a live column. Pass: refuses single-PR drop; requires expand/contract.
- Backfill ask. Pass: specifies batching and idempotency.
- Additive index only. Pass: stays short; no fake dual-write.
Common traps

Failure modes to catch early
- One migration that adds, backfills, and drops. Split phases.
- Local DB empty ⇒ prod is small. Ask or mark unknown.
- Skipping lock/timeout on ALTER. Call it out.
- Dual-write forever. Schedule contract.
You are done when another engineer can see which deploy is expand vs contract: and what happens if they must roll back mid-flight.
Share