c/agents › command
0votes

Claude Code subagent: database migration checker

Template Tested
submitted by CommandVault editors to c/agents · 1 use

A .claude/agents/migration-checker.md that reviews migrations for locks, data loss and rollback.

Template · 2 variables
---
name: migration-checker
description: Reviews new database migrations for locking, data loss, compatibility and rollback before they run. Use whenever a migration is added or changed.
tools: Read, Grep, Glob
---

You review migrations in `{{migrations_path}}` for a {{database}} database with large tables.

For each new migration report:
1. Statements that take long or exclusive locks (column type changes, non-concurrent indexes, constraints added without NOT VALID, SET NOT NULL on a big table; on PostgreSQL 11+ adding a column with a constant DEFAULT is not a rewrite).
2. Anything that drops or rewrites data, and whether it's reversible.
3. Whether currently deployed code keeps working during and after it (expand → backfill → contract).
4. Missing indexes for new foreign keys or filters.
5. The exact rollback steps, as SQL statements.
Finish with GO / NO-GO. Never run migrations yourself.
0 commentsreport

Guide

What you get: Before a migration runs, the subagent reports long locks, data loss, compatibility with deployed code, missing indexes and rollback steps, and ends with GO / NO-GO, without editing files or running migrations. Best for Teams running schema migrations against large production tables..

Before you start

  • Claude Code: save as .claude/agents/migration-checker.md
  • Fill migrations_path and database (we used db/migrations and PostgreSQL 16)
  • Codex: save as .codex/agents/migration-checker.toml (name, description, developer_instructions); in our run Codex didn't load it as an agent role

Worked example (Nov 14, 2026, Claude Code 2.1.318 (claude-opus-5-5); Codex 0.151.0 (gpt-5.6-sol))

Input

crumb-orders: a 40M-row orders table; new untracked migration 0007 adds fulfillment_status NOT NULL DEFAULT 'pending', changes total_cents to bigint, adds a non-concurrent index, creates order_events without an index on order_id, copies notes and drops legacy_notes (still read by src/orders.js), and adds a validated FK. Prompt: 'Use the migration-checker subagent to review the new migration in db/migrations before we deploy it tonight.'

Result

Claude Code (subagent): "Verdict: NO-GO for tonight." Critical: DROP COLUMN legacy_notes breaks src/orders.js:6; int to bigint rewrites 40M rows under ACCESS EXCLUSIVE. Then non-concurrent index, FK without NOT VALID, missing order_events(order_id) index, exact rollback SQL. Codex: "NO-GO for tonight" with the same blockers.

Claude Code delegated to the migration-checker subagent, which used only Glob, Grep and Read; file hashes were identical before and after both runs and nothing was executed against a database. It found all six planted problems, correctly said the constant-DEFAULT column is not a rewrite on PG 11+, and gave exact rollback statements. Codex found the same blockers but FAILED as an agent test: spawn_agent was called without an agent type and the child had agent_role=null, so the .codex/agents file was not used as a role (the child only saw its text because the parent printed the file before forking); it also gave no exact rollback steps, only 'a verified backup/PITR recovery path is required'. After this test the lock list was corrected (a constant DEFAULT isn't a table rewrite on PostgreSQL 11+) and rollback steps must be SQL.

How to check it worked

  • Plant a known-bad statement (DROP COLUMN still used by code) and check it's flagged
  • Check git status / file hashes: the agent must not edit anything
  • Check the report ends with GO or NO-GO and lists rollback statements

Common problems

  • Template item 1 calls 'adding NOT NULL with defaults' a long lock; on PostgreSQL 11+ a constant default is metadata-only
  • Codex may not load project agent TOML files as roles; check its session for agent_role

Add this subagent to your AI tool

Converted for each tool's agent format. Fill in the blanks above first.

One command
npx commandvault add claude-code-subagent-database-migration-checker-ff16bd58 --tool claude
Save as .claude/agents/migration-checker.md
---
name: migration-checker
description: Reviews new database migrations for locking, data loss, compatibility and rollback before they run. Use whenever a migration is added or changed.
tools: Read, Grep, Glob
---

You review migrations in `{{migrations_path}}` for a {{database}} database with large tables.

For each new migration report:
1. Statements that take long or exclusive locks (column type changes, non-concurrent indexes, constraints added without NOT VALID, SET NOT NULL on a big table; on PostgreSQL 11+ adding a column with a constant DEFAULT is not a rewrite).
2. Anything that drops or rewrites data, and whether it's reversible.
3. Whether currently deployed code keeps working during and after it (expand → backfill → contract).
4. Missing indexes for new foreign keys or filters.
5. The exact rollback steps, as SQL statements.
Finish with GO / NO-GO. Never run migrations yourself.

Use it: Claude delegates to it when a task matches, or ask: "Use the migration-checker subagent to …".

From Claude Code's docs , checked Oct 17, 2026.

More from c/agents

See all of c/agents →
0 comments

Log in to join the discussion.