Gate database migrations with a review SKILL.md
Cursor or Claude Code applies a SKILL.md before merging SQL or ORM migrations: expand-contract checks, lock risk, rollback path, and a dry-run against staging schema.
A migration skill agents load for any schema PR, a written rollback statement for each forward migration, and verify lines a DBA or on-call can run without reading the whole diff.
- 1
Anchor the skill to your migrate command
The local apply command must match what CI and deploy use. Shadow databases catch issues docker-less laptops miss.
- 2
Require rollback in the PR template
Add a migration section to pull_request_template.md pointing at this skill. No rollback comment means no merge for high-risk tables.
- 3
Dry-run a scary migration in staging
Walk through verify queries from the skill on a staging clone before trusting the agent’s low-risk label.
The prompt to paste
Write SKILL.md for reviewing database migrations before merge. Agents must not add destructive DDL without explicit human approval and a documented rollback. Repository context: [ORM or raw SQL folder e.g. prisma/migrations, drizzle, flyway, rails db/migrate] [how to apply locally: docker compose, shadow DB, migrate command] [production engine: Postgres, MySQL, etc.] Migration in review (describe or paste filename): [forward migration summary] SKILL.md sections: 1. Purpose — schema changes ship with safety checks, not optimism. 2. When to use — any PR touching migrations/, schema.prisma, or DDL; when not to use — docs-only. 3. Required inputs: migration file names, ticket id, expected row counts or table sizes if known [human may provide], deploy window (can this lock?). 4. Review checklist the agent must complete and paste in the PR: - Forward migration SQL or generated steps listed in plain language. - Rollback: either paired down migration exists or explicit DOWN SQL in PR comment — write [missing rollback] if absent. - Lock risk: flag CREATE INDEX CONCURRENTLY vs blocking INDEX, ADD COLUMN DEFAULT on large tables, table rewrites. - Expand-contract: if removing a column or renaming, confirm two-phase plan or mark [unsafe single phase]. - Backfill: if data backfill required, separate job or batched update with batch size and sleep — not one giant UPDATE in deploy migration unless documented. - Permissions: new tables have RLS/policies if the app uses them [confirm pattern]. 5. Steps for the agent: - Read migration and related app code paths that read/write affected columns. - Run migrate against local or shadow DB: [paste command]. - Run application tests touching the models: [paste command]. - Produce PR comment block: Risk level, Rollback steps, Verify queries (e.g. \d table, SELECT count sanity). 6. Two example prompts: add nullable column vs drop column with expand-contract. 7. Pitfalls: silent type coercion, missing indexes on new FKs, running destructive ops in same deploy as code that still reads old column, assuming empty tables in prod. 8. Done means: checklist all items answered, migrate command exit 0 locally, rollback documented or escalated. Rules: - Do not invent table names; use only what appears in the migration paste or repo paths given. - Do not suggest running migrations against production from the agent session. - Markdown only.
ORM-generated migrations hide raw DDL. The skill should tell the agent to open the SQL file, not only the schema diff summary.
Sample case written by Hidden Logic Lab. Not affiliated with Cursor or Claude Code.
More in Coding
Get new cases in your inbox
Weekly notes on new use cases and agent workflows. No product pitches.