Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Migration Review?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/tuvatechvalley-migration-review)
---
name: migration-review
description: Read-only zero-downtime audit of Alembic (alembic/versions/*.py), SQL migrations, and SQLAlchemy Foreign Keys for PostgreSQL lock contention, table rewrites, data-loss operations, missing lock_timeout/statement_timeout, and empty downgrade() functions. Writes MIGRATION_REPORT.md and migration_findings.json.
---
# Migration review (read-only)
Goal: catch PostgreSQL locking, table-rewrite, rollback, and missing-index hazards **before** a migration hits production traffic. Talk to the user in their language; write `MIGRATION_REPORT.md` in English.
**Read-only.** Never edit migrations, models, or run `alembic upgrade` / `downgrade`. Write only the report files.
`<kit>` = `<this skill's folder>/../fastapi-prod-ready`. Read `<kit>/MIGRATIONS-ZERO-DOWNTIME.md` before grading edge cases.
## 1. Run the automated migration & FK audit
```sh
python <kit>/scripts/migration_audit.py <project> --out <report_dir> --no-fail
```
If the user tells you which revision is live in production, add `--since <revision>` so only newer, still-changeable migrations are audited.
This scans `alembic/versions/*.py`, `*.sql`, `alembic/env.py`, and SQLAlchemy ORM models with Python `ast` (zero external packages) and writes `MIGRATION_REPORT.md` and `migration_findings.json`.
## 2. Verify each finding in context
Open each flagged migration and model file and verify:
1. **Index locks:** Does `op.create_index` / `op.drop_index` on an existing table pass `postgresql_concurrently=True` inside `with op.get_context().autocommit_block():`? (Indexes on a brand-new empty table created in the same `upgrade()` are safe.)
2. **NOT NULL & defaults:** Does `op.add_column(..., nullable=False)` have a constant `server_default` (PostgreSQL 11+ fast metadata-only default) instead of a volatile expression or missing default? Does `op.alter_column(..., nullable=False)` use `CHECK (col IS NOT NULL) NOT VALID` -> `VALIDATE CONSTRAINT`?
3. **Destructive & rolling-deploy safety:** Does `op.drop_column`, `op.drop_table`, `op.alter_column(type_=...)`, or column rename break currently running application pods during a rolling deploy? Enforce the expand-and-contract two-release pattern.
4. **Lock & statement timeouts:** Are `SET lock_timeout = '5s'` and `SET statement_timeout = '30s'` enforced in `alembic/env.py` or each DDL migration to prevent lock-queue amplification?
5. **Reversible `downgrade()`:** Does `downgrade()` actually reverse `upgrade()` instead of `pass` / `...` / `NotImplementedError`?
6. **Foreign Key indexes:** Does every SQLAlchemy `ForeignKey(...)` column have `index=True` (or lead a composite `Index` in `__table_args__`)?
## 3. Deliver `MIGRATION_REPORT.md`
Ensure `<report_dir>/MIGRATION_REPORT.md` includes:
1. Verdict (`❌ NOT READY` / `⚠️ ALMOST READY` / `✅ READY`).
2. Verified findings with `file:line`, PostgreSQL lock level (`SHARE`, `ACCESS EXCLUSIVE`), production impact, and zero-downtime replacement snippet.
3. **"Changes to automated findings"** listing any dropped or re-graded items (e.g., an empty staging-only table) and any manual schema risks found.
Reply in chat in 3–6 lines in the user's language: verdict, blocking migrations, safe rollout step, and report path.
## Never
- Run `alembic upgrade` or modify any migration or model file during a review.
- Approve a non-concurrent index or `ALTER COLUMN TYPE` on an existing production table without an explicit maintenance-window note from the user.