← ClaudeAtlas

supabase-migrationslisted

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.
matthull/my-skills · ★ 0 · API & Backend · score 72
Install: claude install-skill matthull/my-skills
# 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 1. **No rollback** - Migrations only go forward 2. **No repeatable migrations** - Cannot re-run modified files (unlike Flyway's `R__` prefix) 3. **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 ```bash # 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 list ``` ## Command Timeouts **CRITICAL:** Supabase commands can be slow. Using insufficient timeouts causes SIGKILL (exit code 137) whi