Review a schema migration for production safety under live traffic — destructive operations (dropped/renamed columns or tables, type narrowing) gated behind expand-contract plans, lock-taking DDL flagged with the specific lock and its duration driver, the deploy-order contract checked both ways (old code on new schema during rollout, new code on old schema during rollback), backfills separated from DDL and batched, and a rollback path stated per migration. Never executes migrations or DDL. Use this skill whenever the user says "review this migration", "is this migration safe", "will this lock the table", "zero-downtime migration", "check the schema change", "expand and contract", "review the EF migration / alembic / prisma migrate diff", or "/migration-safety" — even if they don't name the skill. Distinct from sql-review (T-SQL antipatterns in procs); this reviews SCHEMA CHANGES against live traffic and deploys.
--- name: migration-safety description: Review a schema migration for production safety under live traffic — destructive operations (dropped/renamed columns or tables, type narrowing) gated behind expand-contract plans, lock-taking DDL flagged with the specific lock and its duration driver, the deploy-order contract checked both ways (old code on new schema during rollout, new code on old schema during rollback), backfills separated from DDL and batched, and a rollback path stated per migration. Never executes migrations or DDL. Use this skill whenever the user says "review this migration", "is this migration safe", "will this lock the table", "zero-downtime migration", "check the schema change", "expand and contract", "review the EF migration / alembic / prisma migrate diff", or "/migration-safety" — even if they don't name the skill. Distinct from sql-review (T-SQL antipatterns in procs); this reviews SCHEMA CHANGES against live traffic and deploys. --- # Migration Safety A migration runs once, against the production database, usually mid-deploy, while old and new application code overlap. This skill reviews it for the three ways that goes wrong: **locks** (DDL that blocks traffic), **ordering** (schema and code versions that can't coexist), and **irreversibility** (data destroyed with no path back). The core discipline: every migration is judged against the deploy timeline, not against an empty dev database where everything is instant and nothing is watching. ## When to use this skill - The user says "review this migration", "is this migration safe", "will this lock the table", "zero-downtime", "expand and contract", "check the schema change", "/migration-safety". - A migration file (EF Core, Prisma, alembic, Rails, Flyway, raw DDL) sits in the diff. - `ship-it` flags a migration and it needs the dedicated pass. Do **not** auto-trigger for stored-procedure or query changes (`sql-review`) or for greenfield schemas with no production data — on an empty database most of this catalog is N/A, and the report should say that in one line instead of performing the checklist. This skill **never executes** migrations, DDL, or any SQL against a database — it reads files and reports. ## Workflow 1. **Establish the context the file doesn't show.** Which engine (Postgres/MySQL/SQL Server/SQLite — lock behavior differs by engine and version, and a lock claim that doesn't name the engine is a guess)? Is there production data, and are the touched tables large or hot? Get evidence where possible (the user, a row-count comment, table names like `events`/`audit_log` that are large by nature) — otherwise label the assumption out loud: "assuming `orders` is large and hot; if it's small, findings 2–3 downgrade to noise." How do migrations deploy relative to code (before app deploy? in the same release?) — this determines step 4's ordering checks. 2. **Walk the destructive-operation gate.** `DROP COLUMN`/`DROP TABLE`, column/table **renames** (a rename IS a drop+add to running code), type **narrowing** (`varchar(500)→(50)`, `bigint→int`, nullable→`NOT NULL`), truncates, and `DELETE`/`UPDATE` data mutations. Each is a **blocker unless** an expand-contract plan is stated: expand (add the new thing, dual-write or backfill), migrate readers, contract (drop the old thing **in a later release**, after old code is provably gone). Drop-in-the-same-release-as-the-code-change fails the rollback test by construction. - ❌ "Renamed `users.name` to `users.full_name` in one migration — the ORM was updated too, so it's fine." - ✅ "Rename is drop+add to the old code still running during rollout: add `full_name`, backfill, deploy code reading `full_name` (writing both), then drop `name` in release N+2. Or, if the deploy has real downtime, say so and the one-step rename is fine — name the assumption." 3. **Flag lock-taking DDL with the specific mechanism.** Name the lock and what drives its duration — "might be slow" is not a finding. The high-yield catalog: index creation without `CONCURRENTLY` (Postgres: blocks writes for the whole build) or `ONLINE = ON` (SQL Server, edition-permitting); `NOT NULL` added without engine-appropriate staging (Postgres: `ADD CONSTRAINT ... NOT VALID` then `VALIDATE`; adding a column `NOT NULL` **with** a constant default is metadata-only on modern PG/SQL Server — don't flag what's actually free, that's severity inflation); full-table-rewrite type changes; adding an FK without `NOT VALID`+`VALIDATE`; MySQL DDL without an online strategy on big tables. For each: the operation, the lock, the duration driver (table size, write rate), and the non-blocking alternative. 4. **Check the deploy-order contract both ways.** During rollout, **old code runs against the new schema** — every added `NOT NULL`-without-default, dropped column old code still selects, or renamed anything breaks it. During rollback, **new-ish data meets old schema expectations** — rows written by new code must not violate what old code assumes. Trace both directions against the actual code in the diff (grep for the column names old code uses). Also: does anything in the release *require* the migration to have run (new code reading a column that doesn't exist yet) — if so the migrate-then-deploy ordering is load-bearing; say it. 5. **Separate backfills from DDL.** Data backfills inside the schema migration (same transaction as DDL, or a single `UPDATE table SET ...` over millions of rows) are findings: long transactions hold locks, bloat undo/WAL, and can't checkpoint. Recommendation shape: DDL migration adds the nullable column; a separate batched job (with progress + resumability) backfills; a later migration adds the constraint. Small-table backfills are fine — say why (the size evidence or assumption from step 1). 6. **Demand the rollback path, per migration.** Three honest answers: (a) reversible — the down-migration exists and actually restores (auto-generated downs that drop a column do NOT restore its data — a down that loses data is not a rollback, label it); (b) roll-forward-only — irreversible by nature, so the plan is a fixing migration, and the deploy gate should know; (c) backup-gated — destructive step requires a named backup/snapshot beforehand. "It has a down file" without reading it is not an answer. 7. **Report.** Findings ranked **blocker** (data loss without a stated plan, traffic-blocking lock on a hot table, rollout/rollback contradiction) / **should-fix** / **note**, each with `file:line`, the failure scenario in one sentence (deploy does X → traffic sees Y), and the safe alternative. State the assumptions from step 1 that findings hang on. A green report on an additive, defaulted, indexed-concurrently migration is a valid outcome — two lines, not a performed checklist. Never edit or execute anything unprompted; ask per-finding whether to draft the fix. ## Examples ### Example 1: the innocent-looking rename **User:** "Review this EF migration before I merge — just renames a column and adds an index." **Claude:** Flags the rename as drop+add against live old code (blocker, expand-contract plan sketched across 3 releases), checks the index: `CreateIndex` on `Orders` — SQL Server without `ONLINE = ON`; asks/flags edition support, cites the line. Checks the down: `RenameColumn` back — actually reversible, noted. One assumption stated: `Orders` presumed hot. ### Example 2: honest green **User:** "Is this migration safe? Adds a nullable `preferences` jsonb column and a partial index CONCURRENTLY." **Claude:** Nullable add = metadata-only; `CONCURRENTLY` = non-blocking (notes it must run outside a transaction — verifies the tool's migration wrapper handles that, cites how); old code unaffected (column unreferenced by it), rollback trivial. Report: no findings, one note about the transaction wrapper. Done in four lines. ## Anti-patterns - ❌ Reviewing the migration against an empty dev database mentally — every finding is judged against size, traffic, and the deploy overlap, or labeled with the assumption. - ❌ Lock claims without the engine — `ADD COLUMN NOT NULL DEFAULT` is free on modern Postgres and was a rewrite on old versions; flagging the free case is severity inflation that erodes trust in the real findings. - ❌ Accepting a rename or drop because "the code was updated in the same PR" — the whole problem is the minutes-to-hours when old code and new schema coexist. - ❌ Trusting an auto-generated down-migration as a rollback without reading whether it restores data or just shape. - ❌ Letting a million-row backfill ride inside the DDL transaction because the migration tool put it there. - ❌ Executing the migration, `dotnet ef database update`, or ANY SQL "to check" — this skill reads and reports, full stop. - ❌ Performing the full checklist on a pre-production empty schema — one line of N/A beats a page of theater. - ✅ Engine-named lock findings, both-direction deploy-order trace, data-preserving rollback verdicts, assumptions stated, blockers with one-sentence failure scenarios. ## Notes - Tool wrappers matter: some runners wrap every migration in a transaction (breaking `CREATE INDEX CONCURRENTLY`), some apply timeouts, some (SQL Server) do transactional DDL. Find the runner's config in the repo before asserting behavior — a claim about the wrapper you haven't opened is a hypothesis. - Recommend `lock_timeout`/`statement_timeout` guards (Postgres) on DDL touching hot tables where the repo's runner supports it — a migration that fails fast beats one that queues behind a long transaction and blocks everything behind *it*. - Apply `think-like-fable`: the risk lives in the destructive ops and the deploy overlap, so they get the effort; every lock/rollback claim is re-derived from the engine + the actual file; the report leads with the one migration that must not run as-is.
don't have the plugin yet? install it then click "run inline in claude" again.
extracted implicit decision logic into explicit if-else branches (greenfield skips, missing engine/code confirmed, backfill thresholds), mapped engine-specific lock behavior (Postgres, MySQL, SQL Server, SQLite), structured procedure steps with explicit inputs and outputs, added deploy-order trace requirements with grep evidence, clarified rollback verdict verdicts, and formalized output structure with assumptions and outcome signals.
A migration runs once, against the production database, usually mid-deploy, while old and new application code overlap. This skill reviews it for the three ways that goes wrong: locks (DDL that blocks traffic), ordering (schema and code versions that can't coexist), and irreversibility (data destroyed with no path back). The core discipline: every migration is judged against the deploy timeline, not against an empty dev database where everything is instant and nothing is watching.
Review schema migrations for production safety under live traffic. the goal is to surface three failure modes: locks that block traffic, deploy-order breaks (old code hits new schema, or new data hits old code), and irreversible data loss. this skill does not execute migrations, DDL, or any SQL against a database. trigger it when the user says "review this migration", "is this safe", "will this lock the table", "zero-downtime", "expand and contract", "check the schema change", or names a migration file (EF Core, Prisma, alembic, Rails, Flyway, raw DDL). skip greenfield empty-database schemas (no production data) in one line; skip stored-procedure logic to sql-review.
events table, orders, audit_log). ask the user, grep for size hints in comments or test data, or state the assumption ("assuming orders is large and hot; if <1M rows, findings 2-3 downgrade to noise").appsettings.json, flyway.conf, alembic env.py) for settings that affect lock behavior. a claim about the tool without opening the config is a hypothesis; say so.Establish the production context the file doesn't show. Which database engine and version? is there production data? size and traffic pattern of the touched tables? deploy ordering (migration before or after code deploy, same release or separate?)? get evidence where possible (user statement, row-count comments, table names by convention); otherwise state the assumption out loud: "assuming orders is large and hot; if it's small, findings 2-3 downgrade to noise." a green report hinges on assumption accuracy, so flag them all and ask if any are wrong.
Walk the destructive-operation gate. scan for DROP COLUMN, DROP TABLE, column or table renames (a rename IS drop+add to running code), type narrowing (varchar(500)→(50), bigint→int, nullable→NOT NULL), truncates, and DELETE/UPDATE data mutations. each is a blocker unless an expand-contract plan is stated: add the new thing (dual-write or backfill), migrate readers to it, drop the old thing in a later release after old code is provably gone. drop-in-the-same-release-as-the-code-change fails the rollback test by construction.
users.name to users.full_name in one migration, the ORM was updated too, so it's fine." (old code still running during rollout queries the old column; it's gone.)full_name, backfill, deploy code reading full_name (writing both), then drop name in release N+2." or, "deploy has real downtime; one-step rename is fine, downtime stated as assumption."Flag lock-taking DDL with the specific mechanism. name the lock and what drives its duration. "might be slow" is not a finding. map each operation to the engine's behavior:
CREATE INDEX without CONCURRENTLY blocks writes for the whole build. ADD COLUMN NOT NULL without a constant default requires a table rewrite (old PG versions; modern versions with a default are metadata-only). ADD CONSTRAINT ... FOREIGN KEY without NOT VALID validates immediately, scanning the whole table. ALTER COLUMN ... SET NOT NULL requires a check scan on old versions.ALTER TABLE ... ADD COLUMN NOT NULL DEFAULT (or any NOT NULL without default) rewrites the table on most versions; online DDL algorithms vary by version and config. index creation blocks writes unless ALGORITHM=INPLACE, LOCK=NONE is explicitly set. FK adds may require validation.ADD COLUMN NOT NULL DEFAULT (with a constant default) is metadata-only. index creation blocks writes unless ONLINE = ON is set (and edition permits it). adding a constraint may require validation.for each finding: the operation, the lock type (table lock, write lock, metadata lock), the duration driver (table size, write rate, index size), and the non-blocking alternative (or "unavoidable, plan downtime").
Check the deploy-order contract both ways.
Separate backfills from DDL and check batching. data backfills inside the schema migration (same transaction as DDL, or a single UPDATE table SET ... over millions of rows) are findings: long transactions hold locks, bloat undo/WAL, and can't checkpoint. if a backfill is present and the table is large (assume >100k rows unless stated otherwise), the finding is: DDL migration adds the nullable column; a separate batched job (with progress tracking, resumability, and batching loop, e.g. UPDATE ... WHERE id BETWEEN X AND Y LIMIT 1000) backfills in a later deployment; a third migration adds the constraint. small-table backfills (<100k rows, with evidence) are fine; note why.
Demand the rollback path, per migration. three honest answers:
"it has a down file" without reading it is not an answer.
Report. structure each finding with file:line, the failure scenario in one sentence (deploy does X, traffic sees Y, or old code hits Z), and the safe alternative. rank findings:
CONCURRENTLY, use NOT VALID, etc.).state the assumptions from step 1 that findings hang on. a green report on an additive, defaulted, indexed-concurrently migration is a valid outcome (two-to-four lines, not a performed checklist). never edit or execute anything unprompted; for each blocker or should-fix, ask whether to draft the fix.
if the user says "review this migration" but the file is a greenfield schema with no production data: output one line ("greenfield schema, no production data, all findings N/A") and stop. the whole catalog is shaped for live-traffic risk; empty databases don't have it.
if the database engine is not named: ask, or assume Postgres 12+ and state the assumption. lock behavior is engine-specific, and a claim without the engine is a guess.
if the migration file exists but the code changes (model/ORM files) are not in the diff: ask the user to include them, or note "code changes not visible; deploy-order check is incomplete" and reduce confidence in step 4.
if a destructive operation (drop, rename, type narrowing) is found and no expand-contract plan is stated: flag as blocker. if the user says "the code was updated in the same PR", explain: the problem is the overlap during rollout; old code is still running when the migration applies; renaming or dropping in one release breaks it. offer to sketch a three-release expand-contract plan.
if a backfill is inside the migration transaction (or a single large UPDATE over millions of rows): ask the table size and write rate. if large and hot, flag as should-fix and recommend batching. if small (<100k rows confirmed), note as acceptable.
if a lock-taking operation is found and the tool's config has not been checked: note "tool config not reviewed; re-check Postgres CREATE INDEX CONCURRENTLY support in [config file name]" or equivalent before shipping.
if the rollback path is not stated or the down-migration is auto-generated: read the down file. if it's reversible, note it. if it loses data, flag as roll-forward-only and demand a backup plan in the deployment playbook.
if old code is not visible (the code diff is missing): note "code changes not visible; can't fully verify deploy-order. if old code still selects [column name], it will error. confirm in code review or resubmit with model changes."
deliver a written report with the following structure:
no code execution. no DDL against any database. no "it looks fine" without tracing both deploy directions. a report that re-derives every lock claim and rollback assumption from the engine and the file is the target.
the user knows the skill worked if:
a green report is two to four lines for a safe additive migration, not a performed checklist. a red report names the one operation that cannot ship as-is and sketches the fix.
original author: clawhub.