Engineering

Schema Migration Dry Run

Make the database change prove itself somewhere safer than the real thing.

Use when

A schema change, backfill, cleanup script, or bulk edit could corrupt data, lock tables, or surprise users if run directly in production.

Advanceddifficulty
Engineeringcategory
Mia daily expansionsource

Cadence

Before production database migrations or bulk data changes

Verification

Migration runs cleanly on a recent snapshot or staging clone, row counts and sample records match expectations, rollback is documented, and production execution remains approval-gated.

Structured loop spec

FieldValue
NameSchema Migration Dry Run
CategoryEngineering
TriggerBefore production database migrations or bulk data changes
ObjectiveMake the database change prove itself somewhere safer than the real thing.
Allowed inputsRelevant files, source notes, logs, tests, screenshots, metrics, or task state for this loop
Allowed actionsState the intended data shape, affected tables, expected row counts, downtime assumptions, and explicit non-goals.; Run the migration or script against a recent snapshot, staging clone, or disposable local copy with production-like constraints.; Compare before/after schema, counts, sampled records, indexes, permissions, and application queries for the touched paths.; Write the rollback or forward-fix plan, including what evidence would trigger it.; Do not run against production, delete data, or change live schedules without explicit approval and a named operator.
VerificationMigration runs cleanly on a recent snapshot or staging clone, row counts and sample records match expectations, rollback is documented, and production execution remains approval-gated.
Stop conditionStop when the verifier passes, the budget is exhausted, no progress is made, a blocker appears, or approval is required.
BudgetSet a time, turn, token, retry, file, or dollar cap before running the loop.
Approval boundaryHuman approval required before publishing, sending, deleting, spending, changing accounts, touching production, or making reputational/legal/financial commitments.
Safe outputPull request, patch, report, or evidence log
Works withClaude Code, OpenAI Codex, Cursor, Gemini CLI, any tool-using coding agent

Steps

  1. State the intended data shape, affected tables, expected row counts, downtime assumptions, and explicit non-goals.
  2. Run the migration or script against a recent snapshot, staging clone, or disposable local copy with production-like constraints.
  3. Compare before/after schema, counts, sampled records, indexes, permissions, and application queries for the touched paths.
  4. Write the rollback or forward-fix plan, including what evidence would trigger it.
  5. Do not run against production, delete data, or change live schedules without explicit approval and a named operator.

Prompt

Run the Schema Migration Dry Run loop. Before any production database migration, backfill, cleanup script, or bulk edit, state the target shape, affected tables, expected row counts, risks, and non-goals. Execute against a recent snapshot, staging clone, or disposable local copy first. Compare before/after schema, counts, sampled records, indexes, permissions, and touched application queries. Produce rollback or forward-fix steps and stop for explicit approval before production execution, destructive changes, or live schedule changes.

Run in Claude Code

Paste this into Claude Code (or any tool-using agent) to run the loop bounded: one change per round, the same verification every round, durable state files, and explicit stop conditions.

Run the "Schema Migration Dry Run" loop from AI Loop Library (https://ailooplibrary.com/loops/schema-migration-dry-run/) as a bounded loop.
Goal: Make the database change prove itself somewhere safer than the real thing.
Rules: one change per round; run the same verification every round (Migration runs cleanly on a recent snapshot or staging clone, row counts and sample records match expectations, rollback is documented, and production execution remains approval-gated.); append each round to docs/loops/schema-migration-dry-run/progress.md and update docs/loops/schema-migration-dry-run/state.json; stop on verifier pass, 8 rounds, 3 consecutive failed verifications, no progress, a blocker, or anything needing human approval (money, production, outbound, deletion). Finish with a proof report: rounds used, changes made, verification output, remaining risk, and the next human decision.

Get the MCP server + agent pack

Tags

databasemigrationsrollbackdata safety

Related

Back to all examples