agentleFS
nfeuernfeuer/project-foundation-kit/.claude/skills/migration-check/SKILL.md

migration-check

Skill0 starsChanged 4 months agoMITView on GitHub

Catch dangerous DB schema migrations before they hit the primary DB or any replica — verify single head, reversibility, and no unguarded destructive ops

  • Deletes or force-pushes

The file

We split this skill into the rules it gives an agent

4 rules. About 0 are common, 1 is distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    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:

    Run this as part of pre-pr whenever a PR touches */versions/* (Alembic) or any equivalent migration directory.

    line 17
  2. Very specific:

    If the output is empty, this skill is done — report New migration files: none — done and skip steps 2–6.

    line 37
  3. Distinctive:

    Add column as NULLABLE — deploy.

    line 86
  4. Very specific:

    Add NOT NULL constraint in a follow-up migration after backfill completes.

    line 88

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “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 Check

Applies when capabilities.migrations.enabled is true (else skip, report N/A).

Profile-driven. The migration tool command comes from capabilities.migrations.heads_cmd and the file-path glob from capabilities.migrations.versions_glob in .claude/kit.yaml; edit the profile to adapt to Flyway, Prisma, or any other tool.

Run this as part of pre-pr whenever a PR touches */versions/* (Alembic) or any equivalent migration directory. Its job is to stop a destructive or un-reversible migration from reaching the primary DB and, for projects that write-through to a replica, from causing a replica divergence that is painful to recover from. Catch these locally, not mid-deploy. It reports findings and mitigations; it does not run alembic merge heads, edit downgrade() bodies, or apply schema fixes itself — those changes stay the author's to make.

Language-agnostic: the same three invariants apply to any migration tool (Django, Flyway, Liquibase, Prisma Migrate, sqitch): (1) single active head, (2) every migration is reversible, (3) no unguarded destructive ops. Substitute your tool's heads / status command and grep over the files it generates.

Workflow

1. Identify new migration files in this branch

# path glob: capabilities.migrations.versions_glob
git diff main...HEAD --name-only -- '*/versions/*'

If the output is empty, this skill is done — report New migration files: none — done and skip steps 2–6.

Only continue with steps 2–6 when step 1 found at least one file.

2. Confirm exactly one migration head

# kit.yaml → capabilities.migrations.heads_cmd
uv run alembic heads

More than one head means two branches added migrations independently and neither created a merge migration. Fix: run alembic merge heads -m "merge_heads" and commit the result before opening the PR.

3. Confirm every new migration has a down_revision and a non-trivial downgrade()

# List new files
NEW=$(git diff main...HEAD --name-only -- '*/versions/*')

# Flag any file where downgrade() body is only 'pass' (anchored to avoid false positives
# on comments containing "bypass", "password", etc.)
while IFS= read -r f; do
  grep -A 5 'def downgrade' "$f" | grep -qE '^[[:space:]]*pass[[:space:]]*$' && echo "TRIVIAL DOWNGRADE: $f"
done <<< "$NEW"

A pass-body downgrade() is not a downgrade — it is a trap. If rolling back is genuinely impossible, that must be an explicit comment with a documented runbook, not a silent no-op.

4. Flag destructive ops

git diff main...HEAD -- '*/versions/*' | grep -iE \
  '(DROP TABLE|DROP COLUMN|RENAME TABLE|RENAME COLUMN|ALTER.*TYPE|ALTER.*USING)'

Each hit requires a human decision. The standard mitigations:

PatternRiskMitigation
DROP TABLEdata lossverify backfill/archive landed in a prior migration, add safety check
DROP COLUMNdata losstwo-migration strategy: nullify → deploy → drop
RENAME TABLE/COLUMNbreaks readersadd alias view or migrate readers first
ALTER COLUMN TYPE (narrowing)truncation / errorswiden first, backfill, narrow in follow-up

5. Flag NOT NULL additions without a server_default or backfill

git diff main...HEAD -- '*/versions/*' | grep -iE 'NOT NULL|server_default|nullable=False'

Adding a NOT NULL column to a populated table without a server_default fails on Postgres and SQLite alike. The safe sequence:

  1. Add column as NULLABLE — deploy.
  2. Backfill existing rows (in a separate migration or a data script).
  3. Add NOT NULL constraint in a follow-up migration after backfill completes.

6. Flag data migrations on large tables (lock risk)

git diff main...HEAD -- '*/versions/*' | grep -iE \
  'op\.execute|connection\.execute|UPDATE|INSERT.*SELECT'

Bulk DML in a migration acquires locks for the full duration. Flag any UPDATE <table> SET ... where the table could be large. Mitigation: batched updates outside the migration (a background job), or LOCK_TIMEOUT + retry.

Output

## Migration Check

- [ ] New migration files: <list or "none — done">
- [ ] Single head: <rev / MULTIPLE — merge needed>
- [ ] All downgrades non-trivial: <yes / FLAGGED: <files>>
- [ ] Destructive ops: <none / FLAGGED: <ops + files>>
- [ ] NOT NULL safety: <clean / FLAGGED: <columns + files>>
- [ ] Lock-risk DML: <none / FLAGGED: <tables + files>>

Verdict: PASS / BLOCK — <blocking issues with suggested fix>

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.