Migration & Contract Review

VerifiedSafe

Blocking review of DB migrations and API contracts: immutability of applied migrations, backward compatibility on rollback, CONCURRENTLY indexes and NOT VALID constraints.

Sby Skills Guide Bot
DevelopmentAdvanced
11/1/2026
Claude CodeCursorCodex
#database-migrations#backward-compatibility#api-contracts#code-review#postgres

Recommended for

Automated summary

Reviews database migrations and API, DTO or event contracts to confirm the previous release's code still works against the change, so a rollback does not turn into an outage.

Strengths

  • Clearly separates blocking checks from contract checks, with concrete SQL counter-examples for each rule.
  • Lays out the expand/contract sequence: stop writing, deploy, confirm no readers remain, then drop in a later task with an explicit deploy dependency.
  • Captures PostgreSQL-specific performance traps: volatile defaults that rewrite the table, indexes built without CONCURRENTLY, constraints missing NOT VALID plus a later VALIDATE.
  • Extends the review to exposed contracts, including mobile clients that cannot be force-updated.

Limitations

  • Guidance is heavily PostgreSQL-specific (PG11+/PG12+ behaviour, CONCURRENTLY, NOT VALID); MySQL or SQLite need different safe-migration patterns.
  • It is a manual review checklist with no scripts or automated checks to enforce it.
  • The document cuts off mid-sentence at consumer discovery, so the tooling for finding consumers is not fully specified.
When to use it

Use it when reviewing a diff or design that adds or changes a migration, an endpoint, a DTO, an event payload or a shared type with consumers.

When not to use it

Skip it for purely internal changes that touch neither schema nor consumers, or for stores without versioned migrations.

Security analysis

Safe
Quality score86/100

The file is purely instructional review guidance: no executable commands, no shell pipelines, no network or credential handling, no obfuscation, and nothing that disables safety. It references abstract reviewer actions (grep_code, list_links, cross-repo clone) only as conceptual checks, not as runnable directives, and the only quoted SQL is illustrative anti-patterns shown as things NOT to ship.

No concerns found

How this analysis is made

Examples

Rollback-safe column drop
Review this PR: it adds `ALTER TABLE tasks ADD COLUMN priority int NOT NULL` and drops `legacy_status` in the same migration. Is the previous release's code still safe if we roll back?
Renamed response field
We renamed `userName` to `username` in the /v1/profile response. Find every consumer and tell me whether this can ship in one task or needs an ordered expand/contract sequence.
Index build in a transactional runner
Our migration runner wraps each file in a single transaction. Is `CREATE INDEX CONCURRENTLY idx_tasks_status ON tasks(status)` safe there, and what is the alternative?

name: migration-and-contract-review category: quality description: Use when a diff or design adds or changes a DB migration, an endpoint or DTO, an event payload, or a shared type with consumers source: sbdchd/squawk docs (Apache-2.0), ankane/strong_migrations (MIT), Google AIP-180 (CC BY 4.0), adapted

Migration & Contract Review

Why It Matters Here

A production rollback reverts the merge commit — it does not undo the schema. The old code has to keep running against the new schema until a human decides otherwise, and the system already flags a schema-touching task for a mandatory stage deploy. A migration or contract reviewed only for "does it run" and not "does the PREVIOUS release's code still work against it" is an outage waiting for the next rollback.

Pair with migration-safety (backend-developer, same rules from the authoring side) and spec-authoring's Security & data / Decision record sections for the design-time version of this.

Blocking Checks (Important or Critical)

Editing an applied migration. A migration already run on any environment is immutable; a fix is a new migration.

  • ❌ editing 0042_add_status.sql after it merged.
  • ✅ 0051_fix_status_default.sql that corrects it.

A stub or empty down/rollback migration. If it can't really be undone, say so and give the operational alternative instead of a down migration that lies.

Drop, rename or retype of a column or table still read by deployed code.

  • ❌ ALTER TABLE tasks DROP COLUMN legacy_status; in the same task that stops writing it.
  • ✅ stop writing it (task N), deploy, confirm no reads remain (grep_code/consumer check), THEN drop it (task N+1, deploy_depends_on: ["N"]).

ADD COLUMN … NOT NULL with no default, or a volatile default (rewrites the whole table).

  • ❌ ALTER TABLE tasks ADD COLUMN priority int NOT NULL;
  • ✅ ALTER TABLE tasks ADD COLUMN priority int NOT NULL DEFAULT 0; — a constant default on PG11+ does not rewrite the table.

CREATE INDEX without CONCURRENTLY on a table already carrying rows, or CONCURRENTLY used inside a transaction / a multi-statement file the repo's migration runner wraps in one (check how the runner executes a file before assuming CONCURRENTLY is safe there).

  • ❌ CREATE INDEX idx_tasks_status ON tasks(status); on a live table — takes a write lock for the build.
  • ✅ CREATE INDEX CONCURRENTLY idx_tasks_status ON tasks(status);, run outside a transaction.

A FK or CHECK added without NOT VALID + a later VALIDATE.

  • ❌ ALTER TABLE tasks ADD CONSTRAINT fk_project FOREIGN KEY (project_id) REFERENCES projects(id); — locks and scans the whole table.
  • ✅ ADD CONSTRAINT … NOT VALID; then, in a later step/migration, VALIDATE CONSTRAINT fk_project;.

SET NOT NULL on an existing column with no prior validated CHECK (col IS NOT NULL) (PG12+ lets the planner skip the full scan once that check is validated).

A data backfill inside the schema migration, unbatched. Backfill in application code or a batched script, not a single blocking UPDATE in the DDL migration.

A new query path added with no supporting index — works in dev on a handful of rows, locks up in production.

Contract Checks

  • Additive is safe: a new optional response field, a new endpoint, a new optional request field with a default.
  • Breaking needs every consumer updated and ordered: a renamed/removed field, a changed type or status code, a new REQUIRED request field, a changed default page size, a changed enum's meaning.
    • AIP-180: "Old clients must be able to work against newer servers" — source, wire and semantic compatibility all have to hold, not just "it compiles."
  • Mobile clients cannot be force-updated. Anything an already-installed app reads stays readable until a later, separate contract task ships and enough time has passed — never break it in the same task that adds the new shape.
  • Find consumers with list_links(component, direction:"in"), then grep_code in the cloned consumer repo (technical-analysis-workflow's cross-repo clone procedure) for the exact field/endpoint.
  • Error shape and status codes are part of the contract — changing a 404 to a 200-with-null, or a flat error body to a nested one, breaks a consumer's error handling exactly like a renamed field.

Design-Side Application (spec-authoring)

Any schema or contract change in the design gets: the expand step and the contract (breaking) step as SEPARATE tasks in the split, a before_deploy entry on the expand task ("migration N applied on stage"), and a rollback_plan that states plainly that the schema stays and names what still reads it. The contract-breaking task carries deploy_depends_on on every consumer-update task.

Common Mistakes

  • Treating "the migration ran in the task's dev DB" as proof it's safe in production — a live table with real row counts behaves differently under a table rewrite or a non-concurrent index build.
  • Reviewing the SQL in isolation from the code that reads the table — a column drop is safe only once nothing reads it, which is a code fact, not a SQL fact.
  • Accepting "the mobile team will update eventually" as cover for a breaking contract change shipped now.

Red Flags

  • A single migration file both drops a column and the diff still has a reader for it (grep_code the old field name).
  • NOT NULL added to an existing column with no earlier CHECK step.
  • A renamed REST field with no corresponding blocked_by/deploy_depends_on on the consuming repositories' tasks.
  • before_deploy/rollback_plan left empty on a task that HasMigration.

From the file to a first result

The download contains exactly the content displayed on this page. This copy may differ from the latest version in the source repository.

View the source and supporting files

This download contains SKILL.md only. Any scripts, references, templates and dependencies are not included. Get the required files from the source, preserving their directory structure, before continuing.

1. Download the file

Download SKILL.md

From the root of a test project, save the file as .skill-downloads/migration-contract-review-mveraomk/SKILL.md, or use the command below. This folder is for inspecting the skill before installation.

Command for macOS/Linux or WSL: requires a POSIX shell and curl. On Windows without WSL, use the download button and create the folder manually.

mkdir -p '.skill-downloads/migration-contract-review-mveraomk' && curl --fail --show-error --location 'https://skills-guides.com/api/skills/migration-contract-review-mveraomk/download' --output '.skill-downloads/migration-contract-review-mveraomk/SKILL.md.part' && mv '.skill-downloads/migration-contract-review-mveraomk/SKILL.md.part' '.skill-downloads/migration-contract-review-mveraomk/SKILL.md'

2. Check prerequisites

Read SKILL.md before using it. If it references scripts or external services, inspect them and prepare the required access in your test environment.

No recognized prerequisites section in this file. This does not mean it is self-contained: libraries, tools and access requirements may be mentioned elsewhere in the content or source repository.

The platforms on this page are catalog indications. The paths below follow tool documentation; they do not prove this skill has been run in those tools. No minimum tool version is confirmed for this listing.

3. Load the skill

After inspection, copy the complete folder into your project using one of the commands below, then open a new tool session. The command stops if a folder with the same name already exists: compare the files before replacing it.

Claude Code
test -f '.skill-downloads/migration-contract-review-mveraomk/SKILL.md' && test -s '.skill-downloads/migration-contract-review-mveraomk/SKILL.md' && mkdir -p '.claude/skills' && test ! -e '.claude/skills/migration-and-contract-review' && cp -R '.skill-downloads/migration-contract-review-mveraomk' '.claude/skills/migration-and-contract-review'

Cursor
test -f '.skill-downloads/migration-contract-review-mveraomk/SKILL.md' && test -s '.skill-downloads/migration-contract-review-mveraomk/SKILL.md' && mkdir -p '.cursor/skills' && test ! -e '.cursor/skills/migration-and-contract-review' && cp -R '.skill-downloads/migration-contract-review-mveraomk' '.cursor/skills/migration-and-contract-review'

Codex
test -f '.skill-downloads/migration-contract-review-mveraomk/SKILL.md' && test -s '.skill-downloads/migration-contract-review-mveraomk/SKILL.md' && mkdir -p '.agents/skills' && test ! -e '.agents/skills/migration-and-contract-review' && cp -R '.skill-downloads/migration-contract-review-mveraomk' '.agents/skills/migration-and-contract-review'

OpenSkills

OpenSkills must already be installed. The local install/read procedure is checked with OpenSkills 1.5.0, which requires Node.js ≥ 20.6.0. Catalog slugs are not resolved automatically.

Official OpenSkills installation
openskills install './.skill-downloads/migration-contract-review-mveraomk'

openskills read 'migration-contract-review-mveraomk'

Reading should display the installed file content and its base directory. It does not run the skill or install its dependencies.

For an agent that reads AGENTS.md, then sync the index. This command changes AGENTS.md: review the diff before using it.

openskills sync

Manual method or another tool: attach SKILL.md to a conversation, or open it in an agent that can read files. Include any required supporting resources. No universal folder is recognized by every tool.

4. Try a first task

Use a short, synthetic input: an API endpoint, a small document or an interface brief. In a new conversation, attach the file or give the agent its path, then adapt this request:

Read .skill-downloads/migration-contract-review-mveraomk/SKILL.md and apply its instructions to this example: [describe a test input]. Identify any missing files, dependencies or access. Produce the result requested by the skill without inventing data or running unreviewed scripts.

Expected result: output matching the skill instructions, or a precise list of missing prerequisites. A read confirmation alone does not validate a first use. If an external resource is unavailable, that path remains untested.

Related skills