Agent skill · software engineering · aiskillstore
database-migration
Guide for creating idempotent Supabase database migrations with RLS policies and workspace isolation
Why this skill is useful
Provides specific patterns and SQL commands for creating idempotent Supabase migrations that the AI wouldn't reliably generate on its own.
What it needs
About 3k tokens when loaded. Last updated 2026-08-07. 405 stars on the source repository.
What this skill does
Database Migration Skill Creating Idempotent Supabase Migrations When to Use: Adding tables, modifying schemas, creating RLS policies, adding functions --- Process 1. Check Existing Schema ALWAYS check before creating: 2. Create Migration File Location: supabase/migrations/YYYYMMDDHHMMSSdescription.sql Naming: Use timestamp + descriptive name 3. Write Idempotent SQL Pattern: Use IF NOT EXISTS and CREATE OR REPLACE 4. RLS Policy Pattern ALWAYS use: userorganizations + workspaces join (NOT workspacemembers) 5. Apply Migration Method: Supabase Dashboard → SQL Editor Steps: 1. Copy migration SQL 2. Paste into SQL Editor 3. Click "Run" 4. Verify success Alternative: Use WORKINGMIGRATIONS.sql pattern for combined migrations --- Examples Example 1: Simple Table Example 2: ENUM Type Example 3: Trigger --- Common Patterns Workspace Isolation (MANDATORY) Constraints Foreign Keys --- Checklist Before applying migration: [ ] Checked schema-reference.md for conflicts [ ] Used IF NOT EXISTS on tables [ ] Used CREATE OR REPLACE on functions [ ] Added workspaceid column (if multi-tenant table) [ ] Created index on workspaceid [ ] Enabled RLS [ ] Added RLS policies (user + system) [ ] Used correct RLS pattern (userorganizations join) [ ] Added constraints where appropriate [ ] Added comments for documentation [ ] Tested SQL syntax locally --- Troubleshooting Error: "relation workspacemembers does not exist" Fix: Use userorganizations + workspaces join (see RLS pattern above) Error: "already exists" Fix: Use IF NOT EXISTS or CREATE OR REPLACE Error: "permission denied" Fix: Use service role key in Supabase Dashboard, not anon key --- Standard: Idempotent, workspace-isolated, RLS-secured, well-documented
How to use it
Reference it in AdaL, Claude Code, Cursor or any coding agent — nothing to install:
@skills aiskillstore/database-migration