KnowledgeMay 19, 2026·2 min read

Zero-Downtime DB Migration — Expand Contract Checklist

Expand-contract database migration checklist for agents. Covers additive schema changes, batched backfills, rollback, and contract gates.

Agent ready

This asset can be read and installed directly by agents

TokRepo exposes a universal CLI command, install contract, metadata JSON, adapter-aware plan, and raw content links so agents can judge fit, risk, and next actions.

Native · 98/100Policy: allow
Agent surface
Any MCP/CLI agent
Kind
Knowledge
Install
Single
Trust
Verified publisher
Entrypoint
README.md
Universal CLI install command
npx tokrepo install 84ab1d5e-6fa5-42ed-bc57-443b0d997577

Agent Checklist

Before proposing or running a migration, verify:

  1. The first schema change is additive: new nullable column, new table, new index, or new enum shadow table.
  2. Old code can still run after the new schema exists.
  3. New code can run before the backfill is complete.
  4. Backfill runs in bounded batches and can resume safely.
  5. There is a rollback path that does not require restoring the whole database.
  6. Monitoring includes error rate, lock wait, replication lag, row count, and backfill progress.
  7. The contract step is delayed until logs show no reads or writes to the old path.

Batch Backfill Shape

Use small batches with an id cursor:

UPDATE tb_example
SET new_status = old_status
WHERE id > ?
  AND id <= ?
  AND new_status IS NULL;

For MySQL, keep transactions short and watch lock waits. For PostgreSQL, avoid long table rewrites and validate constraints separately when possible. For both, make the job idempotent.

Red Flags

  • DROP COLUMN, RENAME COLUMN, or non-null constraint in the first release.
  • A migration that assumes every app server restarts at the same second.
  • Backfill that scans the whole table in one transaction.
  • Rollback plan that says "restore backup" for an ordinary deploy.
  • No verification query for migrated row counts.
🙏

Source & Thanks

This is an original TokRepo checklist by William Wang. It follows the widely used expand-contract migration pattern documented by Martin Fowler and operational guidance from database migration tools such as gh-ost.

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets