supabase-migrations
Skill0 starsChanged 55 days agoMITView on GitHub
Guidance for writing Supabase database migrations with idempotent patterns. This skill should be used when creating or modifying database objects (tables, functions, RLS policies, triggers, indexes) or any SQL committed as a migration file.
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 1 is distinctive, and 2 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.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 16
Critical rule: Never edit a migration that has already run in any environment.
- Very specific: line 90
Modifying existing function?: Use CREATE OR REPLACE in a new migration file
- Very specific: line 91
Adding index?: Use CREATE INDEX CONCURRENTLY in its own separate migration file (one index per file)
≈ “Common” is an estimate: at least 1 in 5 of the 308,232 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
Supabase Migrations
Supabase uses timestamped SQL migrations in supabase/migrations/. Migrations run once, in order, and cannot be rolled back. This requires idempotent patterns.
Key Constraints
- No rollback - Migrations only go forward
- No repeatable migrations - Cannot re-run modified files (unlike Flyway's
R__prefix) - No checksum validation - System won't detect edits to already-run migrations
Critical rule: Never edit a migration that has already run in any environment. Create a new migration instead.
Pattern Selection
| Object Type | Pattern | Rationale |
| Tables | CREATE TABLE | One-time DDL, never modified after creation |
| Functions | CREATE OR REPLACE FUNCTION | Idempotent, can be updated in new migrations |
| RLS Policies | DROP POLICY IF EXISTS + CREATE POLICY | Policies cannot be replaced, must drop first |
| Triggers | DROP TRIGGER IF EXISTS + CREATE TRIGGER | Same as policies |
| Indexes | CREATE INDEX CONCURRENTLY IF NOT EXISTS | Non-blocking, separate file per index |
Workflow
# Create new migration
npx supabase migration new <name>
# Apply locally (drops everything, runs all migrations + seed)
npx supabase db reset
# Apply pending only (preserves data)
npx supabase db push
# Check status
npx supabase migration listCommand Timeouts
CRITICAL: Supabase commands can be slow. Using insufficient timeouts causes SIGKILL (exit code 137) which looks like a failure but is just a timeout.
| Command | Minimum Timeout | Notes |
supabase db reset | 120s (2 min) | Drops DB, runs all migrations, restarts containers |
supabase db push | 60s | Only applies pending migrations |
supabase migration list | 30s | Quick status check |
supabase status | 30s | Quick status check |
When using Bash tool, always set appropriate timeout:
timeout: 120000 # for db reset (milliseconds)Interpreting Output
Success indicators (look for these, not just exit code):
- "Applying migration XXXXXX_name.sql..." for each migration
- "Finished supabase db reset on branch main."
Warnings (not errors):
WARN: no files matched pattern: supabase/seed.sql- Fine if no seed data yet
Actual errors:
- SQL syntax errors will show the failing statement
- "ERROR: relation X already exists" - Table collision
- "ERROR: column X does not exist" - Schema mismatch
Naming Convention
YYYYMMDDHHMMSS_<action>_<object>.sqlExamples:
20251215100000_create_widgets.sql20251215100001_add_rls_policies.sql20251220100000_update_auth_hook_v2.sql
Checklist Before Completing Migration
- New table, and this project uses PowerSync for offline/mobile sync? Add it to the sync publication:
ALTER PUBLICATION <sync_publication> ADD TABLE new_table; - SECURITY DEFINER / privileged function? Grant and revoke EXECUTE explicitly
- RLS on table? Both
ENABLE ROW LEVEL SECURITYandFORCE ROW LEVEL SECURITYrequired - Modifying existing function? Use
CREATE OR REPLACEin a new migration file - Adding index? Use
CREATE INDEX CONCURRENTLYin its own separate migration file (one index per file)
Detailed Patterns
For structural examples, read references/patterns.md in this skill directory.
Note: Examples show idempotent structure, not business logic. Actual SQL implementation should come from your feature specs and research docs.
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- ASNNetworks/floh-skills★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository43 other files it gives its agents.
- skills/technical/supabase-postgres-best-practices/AGENTS.mdAGENTS.md
- skills/technical/supabase-postgres-best-practices/CLAUDE.mdCLAUDE.md
- direct-handoffSkill
- handoffSkill
- nt-commsSkill
- threadsSkill
- meal-planningSkill
- resume-workflowSkill
- bash-scriptsSkill
- code-reviewSkill
- davinci-resolveSkill
- disk-cleanupSkill
- fastmcp-pythonSkill
- go-cliSkill
- markdown-to-pdfSkill
- pr-createSkill
- qa-planSkill
- rcaSkill
- react-native-best-practicesSkill
- ruby-railsSkill
- skill-creatorSkill
- spec-checkSkill
- supabase-postgres-best-practicesSkill
- supabase-sqlSkill
- testingSkill
- ui-state-managementSkill
- waydroid-adbSkill
- calcinatioSkill
- citationsSkill
- exploreSkill
- manual-qaSkill
- nvim-copilotSkill
- orchestrateSkill
- orthogonal-emanationSkill
- product-intent-signal-extractionSkill
- project-management-signal-extractionSkill
- request-researchSkill
- researchSkill
- skill-discoverySkill
- slack-thread-triageSkill
- specSkill
- tmux-sidecarSkill
- youtube-transcribeSkill
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
Reviews can't be read right now.
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.

