agentleFS
youcislayoucisla/Agent-Foundry/skills/optional/sql-migration-trio/SKILL.md

sql-migration-trio

Skill1 starsChanged 23 days agoMITView on GitHub

'Every SQL migration = three files: up (forward DDL), down (reverse DDL),

The file

We split this skill into the rules it gives an agent

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

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 4

    Very specific

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

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

    Every migration = three files (up .sql, down .sql, schema.sql sync).

    line 15
  2. Very specific:

    Update the project's schema.sql (or equivalent) to match the migration.

    line 39
  3. Distinctive:

    Run database advisors (security + performance) after every DDL change.

    line 61
  4. Very specific:

    Document before deploying: run the .down.sql, PITR snapshot taken before applying.

    line 65
  5. Distinctive:

    Not testing the down file before deploying

    line 80
  6. Very specific:

    Keep one monotonic schema_version row in a schema_meta table.

    line 84
  7. Distinctive:

    Test fresh, old, duplicate-run, and future-version databases in the same suite.

    line 89

≈ “Common” is an estimate: at least 1 in 5 of the 364,980 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

SQL Migration Trio

Every migration = three files (up .sql, down .sql, schema.sql sync). Runs both directions.

When to Use

  • Creating or reviewing any SQL migration
  • Running advisors after DDL changes
  • Investigating migration drift between repo and production

Procedure

1 — Scaffold the trio

TIMESTAMP=$(date +%Y%m%d%H%M%S)
NAME="descriptive_name"
touch "supabase/migrations/${TIMESTAMP}_${NAME}.sql"
touch "supabase/migrations/${TIMESTAMP}_${NAME}.down.sql"
  • Up: begin; -- your DDL here; commit;
  • Down: begin; -- your REVERSE DDL here; commit;

2 — Sync schema.sql

Update the project's schema.sql (or equivalent) to match the migration. CI should check this.

3 — Drift check

-- Applied in prod but NOT in repo
select version, name from supabase_migrations.schema_migrations
where version not in (
  select regexp_replace(f.name, '.down.sql$', ''),
         regexp_replace(f.name, '.sql$', '')
  from pg_catalog.pg_ls_dir('supabase/migrations') f(name)
);

-- Repo files not in applied list
select version, name from supabase_migrations.schema_migrations
  outer join ...

Also check reverse: repo files that are not in the applied list.

4 — Apply + run advisors

Run database advisors (security + performance) after every DDL change.

5 — Rollback plan

Document before deploying: run the .down.sql, PITR snapshot taken before applying.

Verification Checklist

  • Three files: up + down + schema.sql update
  • CI lint passes locally
  • Drift check run — no unexpected ghost migrations
  • Advisors run post-DDL — zero new errors
  • Down file actually reverses the up (test in preview)

Anti-patterns

  • Creating the up file without planning the down first
  • Forgetting to sync schema.sql (CI linter should catch this)
  • Applying without a drift check first
  • Not testing the down file before deploying

Version Discipline

  • Keep one monotonic schema_version row in a schema_meta table.
  • Number every migration and never edit or reorder an applied entry.
  • Refuse to open a database whose stored version is newer than the code understands.
  • Swallow only the duplicate-column case on replay; re-raise every other OperationalError.
  • Migrations are additive by default. Destructive changes require an explicit backup and a separate release.
  • Test fresh, old, duplicate-run, and future-version databases in the same suite.

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.