postgres-migration-review
Created here
Use when a PostgreSQL schema migration should be reviewed before it runs, for blocking locks, table rewrites, data loss and a safe rollout order.
SKILL.md
Review a PostgreSQL schema migration before it runs and say whether it is safe on a live database, with a safer sequence when it is not. It changes nothing.
Arguments
- A migration (required; ask for it when missing): a file, several files, or the pending changes of the project's migration tool.
Flow
- Read the migration and its tool. Find the project's migration tool, whether it wraps each migration in a transaction, and the PostgreSQL major version in use (lock behaviour differs between versions). Read the tables' real sizes and indexes through the
dbhubMCP server when it is available; otherwise say that sizes are unknown. - Check every statement for:
- Locks that block reads or writes for long:
ALTER TABLEthat rewrites the table (a type change, a volatile default),CREATE INDEXwithoutCONCURRENTLY, adding a foreign key or aCHECKwithoutNOT VALID,SET NOT NULLon a large table without a validatedCHECKfirst,VACUUM FULL,CLUSTER, and anyALTER TABLEthat can queue behind a long transaction and then block everyone behind it (nolock_timeout). - Statements that cannot run in a transaction in a tool that opens one, such as
CREATE INDEX CONCURRENTLY. - Data loss:
DROP COLUMN,DROP TABLE, a narrowing type change,TRUNCATE, aDELETEorUPDATEwithout aWHERE. - Large data changes in one statement: a backfill of a big table that should run in batches outside the schema migration.
- Incompatibility with the running application: during a rolling deploy the old code runs against the new schema; a rename, a drop or a new
NOT NULLcolumn without a default breaks it.
- Locks that block reads or writes for long:
- Check the way back: whether the migration can be reverted and what a revert loses.
- Check the project's own rules for migrations (naming, forward-only, one change per file) in its contributing guide.
- For each problem, write the safer sequence: for example add the column as nullable, backfill in batches, add a
CHECK ... NOT VALID, validate it, then setNOT NULL; or expand, migrate the code, then contract across separate deploys.
Report
- Verdict: safe to run, safe with changes, or unsafe, in one sentence.
- Findings, most severe first: the statement, the lock or risk, why it matters at this table's size, and the safer sequence as SQL.
- Deploy order: which steps go before, with and after the code change.
- Revert: how, and what is lost.
- What could not be checked (table sizes, the PostgreSQL version, long-running transactions).
SKILL.md
SKILL.md holds the skill's instructions; it is edited on the Instructions tab.
Frontmatter written into each target's SKILL.md.
Common
No fields set for this target.