Operations Database Migration

Database Migration Plan Prompt

Ship a schema change without downtime or data loss — an expand-migrate-contract migration plan with backward compatibility, ordering, and a reversal path.

Overview

A schema change deployed naively locks tables, breaks the running version, or loses data on rollback. This prompt plans a safe migration using the expand/contract pattern: the backward-compatible expand step, the data backfill, the cutover, and the later contract — each ordered so the old and new code can both run during deploy, with a reversal path at every stage.

How to use this resource

  1. Describe the schema change

    Note the change you are making, the tables and data it touches, and the versions that must keep running during deploy. The plan orders it so old and new code coexist.

  2. Open this resource in Markdown Output Builder

    Load the prompt into Markdown Output Builder and fill in the change. It returns the expand-migrate-contract plan as clean Markdown you can drop into your runbook.

  3. Walk through the migration stages

    Read the backward-compatible expand step, the backfill, the cutover, and the later contract, confirming each carries a reversal path.

  4. Fill the gaps before you migrate

    Resolve any stage without a clean reversal and confirm the ordering keeps both versions working, then run the migration behind it.

Why This Works

  • Expand/contract keeps both code versions working through the deploy
  • Putting drops in a later deploy makes the change reversible when it matters
  • Calling out locking steps prevents the migration that takes the site down

Best for

  • Schema changes on tables with live traffic and real data
  • Deploys where the migration and code ship together
  • Large tables where a naive ALTER would lock

Not for

  • Designing the schema in the first place — use a database design workflow
  • Tuning a slow query — use a SQL optimization prompt

Use cases

  • Planning a zero-downtime schema change
  • Sequencing a migration so old and new code coexist
  • De-risking a destructive column or table change

FAQ

Why does the plan split a schema change into expand, migrate, and contract instead of one migration?

Splitting it lets old and new code both run during the deploy window. The EXPAND step is additive only — new nullable columns and tables, no drops — so the old version keeps working. BACKFILL and CUTOVER move data and reads over, and the destructive CONTRACT (dropping old columns) is deferred to a separate later deploy once nothing uses the old shape.

How does the generated plan keep a large-table migration from locking and taking the site down?

The prompt has a dedicated LOCK & PERFORMANCE section that flags any step that could lock a large table and describes how to avoid it, and the BACKFILL step is specified as batched, resumable, and non-locking rather than a single ALTER. The Markdown Output Builder writes these into your runbook; you still run the actual migration wherever your database lives.

Which migration steps get a rollback path, and what happens with irreversible ones like dropping a column?

The REVERSIBILITY section tags every step as reversible or not and states the reversal action for the ones that are. For irreversible steps it specifies a safeguard instead — a backup or a dual-write window — and the RULES push destructive drops into a separate last deploy, so a failed cutover reverses without having already dropped data.

More resources from Markdown Output Builder

Resources that pair well

Related tools

Guides for this resource

Tip: Save time by exploring related resources and tools that integrate with this resource.