supabase-migration-deep-dive
Supabase Migration Deep Dive
Overview
Supabase migrations are timestamped SQL files managed by the CLI that track schema changes across environments. This skill covers the full lifecycle — creating migrations, zero-downtime schema changes, batch backfills, versioning, rollback, and TypeScript type generation — using real CLI commands and createClient from @supabase/supabase-js.
When to use: Creating new database migrations, modifying production schemas without downtime, backfilling existing data after adding columns, managing migration history across dev/staging/production, rolling back failed migrations, or regenerating TypeScript types.
Prerequisites
- Supabase CLI installed:
npm install -g supabaseornpx supabase --version @supabase/supabase-jsv2+ installed in your project- Local Supabase running:
npx supabase start - Understanding of PostgreSQL DDL and transaction behavior
Instructions
Step 1: Create and Manage Migrations
Create each migration as a timestamped SQL file, write the DDL, test it against a local reset, then promote it through environments with db push: