sql-migration-trio
Skill1 starsChanged 23 days agoMITView on GitHub
'Every SQL migration = three files: up (forward DDL), down (reverse DDL),
In this repository46 other files it gives its agents.
- AGENTS.mdAGENTS.md
- .codex/AGENTS.mdAGENTS.md
- .gemini/AGENTS.mdAGENTS.md
- .cursor/rules/agent-foundry-orchestrator.mdcCursor rule
- .cursor/rules/agent-foundry-skills.mdcCursor rule
- web/llms.txtllms.txt
- anti-slopSkill
- api-designSkill
- automation-pickSkill
- bottleneck-gatingSkill
- budget-guardSkill
- cache-identitySkill
- constraint-then-solveSkill
- context-optimizationSkill
- cron-troubleshootSkill
- e2e-test-strategySkill
- engram-routingSkill
- execution-observabilitySkill
- fallback-model-routingSkill
- feedback-loopSkill
- judge-integritySkill
- knowledge-extractSkill
- landscape-firstSkill
- measure-firstSkill
- plan-before-codeSkill
- plan-then-actSkill
- prompt-disciplineSkill
- pushback-when-wrongSkill
- quality-protocolSkill
- read-before-buildSkill
- re-verify-findingsSkill
- session-closeoutSkill
- session-distillSkill
- show-your-workSkill
- structured-output-contractSkill
- verify-firstSkill
- workflow-decomposeSkill
- agent-memory-vaultSkill
- agent-team-standardsSkill
- autonomous-briefingSkill
- book-to-skillSkill
- chrome-devtools-mcp-bridgeSkill
- design-languageSkill
- funnel-pr-guardSkill
- persistent-memorySkill
- token-compressionSkill
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
- Very specific: line 15
Every migration = three files (up .sql, down .sql, schema.sql sync).
- Very specific: line 39
Update the project's schema.sql (or equivalent) to match the migration.
- Distinctive: line 61
Run database advisors (security + performance) after every DDL change.
- Very specific: line 65
Document before deploying: run the .down.sql, PITR snapshot taken before applying.
- Distinctive: line 80
Not testing the down file before deploying
- Very specific: line 84
Keep one monotonic schema_version row in a schema_meta table.
- Distinctive: line 89
Test fresh, old, duplicate-run, and future-version databases in the same suite.
≈ “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.
Files
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_versionrow in aschema_metatable. - 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.
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
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.

