Cfn migration rehearsal

From masharratt/claude-flow-novice · View interactive version

Cfn migration rehearsal is an AI agent skill from the GitHub repository masharratt/claude-flow-novice. Rehearses a DB migration up+down round-trip against an EXPLICIT scratch database only. Applies up, captures schema, applies down, re-captures, and diffs to prove up and down are inverses. Refuses to run without CFN_SCRATCH_DATABASE_URL and refuses anything that looks like prod. Executes what cfn-ops

How to use this skill

Skill file

CFN Migration Rehearsal

Purpose: cfn-ops DESIGNS the rollback (the up+down pair and the rollback rehearsal step). This skill EXECUTES that rehearsal: it actually applies the up migration, applies the down migration, and proves the schema round-trips back to its starting state. A down migration that does not fully reverse its up is caught here, before merge, on a disposable database, not in production during an incident.

Wired by: this skill is invoked as an executable gate by cfn-loop-task Phase 4 (when the db build flag is set AND migration files appear in the diff — a hard exit-code gate, not advisory), and it is cited as the executable rollback evidence designed by cfn-ops Phase 6 and asserted by cfn-test-plan Phase 3 (the AC-mig row). It runs only against CFN_SCRATCH_DATABASE_URL, never DATABASE_URL.

SAFETY CONTRACT (read first)

This skill runs DDL against a real database. Every guard below runs BEFORE any database connection is opened. If any guard trips, the skill exits non-zero with a clear message and touches nothing.

The scratch database is YOUR responsibility to provision and dispose. A good pattern: a local Postgres container or a dedicated Supabase project used for nothing else.

How It Works

  1. Run all safety guards. Refuse on any failure.
  2. Verify psql and pg_dump are installed (exit non-zero if not).
  3. Capture the baseline schema snapshot (s0) with pg_dump --schema-only, normalized (comments/SET/blank lines stripped, sorted).
  4. Apply the up migration with psql -v ON_ERROR_STOP=1. On error, stop and report.
  5. Capture s1. Note if up produced no schema change.
  6. Apply the down migration. On error, report that up applied but down failed to roll back.
  7. Capture s2.
  8. Diff s0 vs s2:

Inputs

Outputs

Usage

export CFN_SCRATCH_DATABASE_URL="postgres://user:pass@localhost:5433/scratch"

$HOME/.claude/skills/cfn-migration-rehearsal/execute.sh \
  --up   supabase/migrations/0007_orders.up.sql \
  --down supabase/migrations/0007_orders.down.sql

Rules

Related

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.