Esta página se muestra en inglés. Una traducción al español está en curso.
KnowledgeMay 19, 2026·2 min de lectura

Zero-Downtime DB Migration — Expand Contract Checklist

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

Listo para agents

Instalación lista para agent

Este activo puede instalarse después de elegir el runtime, revisar el plan y ejecutar el comando correspondiente.

Native · 98/100Política: permitir
Superficie agent
Cualquier agent MCP/CLI
Tipo
Knowledge
Instalación
Single
Confianza
Publisher verificado
Entrada
README.md
Comando de instalación directa
npx -y tokrepo@latest install 84ab1d5e-6fa5-42ed-bc57-443b0d997577 --target codex

Ejecutar después de confirmar el plan con dry-run.

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.
🙏

Fuente y agradecimientos

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.

Discusión

Inicia sesión para unirte a la discusión.
Aún no hay comentarios. Sé el primero en compartir tus ideas.

Activos relacionados