agentleFS
tuvatechvalleytuvatechvalley/fastapi-prod-ready/skills/migration-review/SKILL.md

migration-review

Skill2 starsChanged 3 days agoMITView on GitHub

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.

7 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

3 rules. 0 are common, 0 are distinctive, and 3 are very specific to this project.

  • 0

    Common

    Most of the 7 edited versions we read keep these.

  • 0

    Distinctive

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Read-only: Never edit migrations, models, or run alembic upgrade / downgrade.

    line 10
  2. Very specific:

    If the user tells you which revision is live in production, add --since <revision> so only newer, still-changeable migrations are audited.

    line 20
  3. Very specific:

    Run alembic upgrade or modify any migration or model file during a review.

    line 46

“Common” is measured: kept by at least 6 in 10 of the 7 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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

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.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.