SU

supabase-migration-deep-dive

A guide to managing database schema evolution, backfills, rollbacks, and type generation using the Supabase CLI.

Install

mkdir -p .claude/skills/supabase-migration-deep-dive && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/5494" && unzip -o skill.zip -d .claude/skills/supabase-migration-deep-dive && rm skill.zip

Installs to .claude/skills/supabase-migration-deep-dive

Activation

This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.

Database migration patterns with the Supabase CLI: npx supabase migration new, zero-downtime migrations, data backfill strategies, schema versioning, rollback strategies, and TypeScript type generation. Use when creating database migrations, performing zero-downtime schema changes, backfilling data in production, managing schema versions, or planning rollback strategies. Trigger with "supabase migration", "supabase schema change", "supabase zero downtime", "supabase rollback", "supabase db push", "supabase migration new".
527 chars✓ has a “when” triggerlonger than Claude Code's old 250-char listing cap (fine on current versions)
Intermediate

Key capabilities

  • Create timestamped SQL migration files
  • Execute zero-downtime schema modifications
  • Perform batch data backfills with rate limiting
  • Implement rollback strategies for failed migrations

How it works

It manages schema evolution through timestamped SQL files and CLI commands that ensure consistent application of changes across development, staging, and production environments.

Inputs & outputs

You give it
SQL schema definitions
You get back
Versioned migration files and updated database schema

When to use supabase-migration-deep-dive

  • Creating database migrations
  • Performing zero-downtime schema changes
  • Backfilling data in production
  • Rolling back failed migrations

About this skill

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 supabase or npx supabase --version
  • @supabase/supabase-js v2+ 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:

npx supabase migration new add_profiles_table   # create timestamped SQL file
npx supabase migration list                      # show applied/pending status
npx supabase db reset                            # apply + seed locally (destructive)
npx supabase gen types typescript --local > lib/database.types.ts
npx supabase link --project-ref "<ref>" && npx supabase db push   # promote to remote

Write DDL that enables RLS, adds policies, indexes, and triggers in the same file so the schema is complete when applied. For the full worked migration (a profiles table with RLS policies, an email index, a signup trigger, and an updated_at trigger) plus the local-test and staging/production promotion commands, see creating migrations.

Step 2: Zero-Downtime Migration Patterns

Production schema changes must avoid locking tables. The core rules: adding a nullable column with a default is lock-free on Postgres 11+; build indexes with CREATE INDEX CONCURRENTLY in a -- supabase:disable-transaction migration; rename or retype a column in two phases (add new column, backfill, sync trigger, then drop the old one) rather than an in-place ALTER COLUMN. Example of the safe column-add:

-- Nullable column with a default does NOT lock the table in Postgres 11+
ALTER TABLE public.orders ADD COLUMN status text DEFAULT 'pending';
-- Then, in a separate -- supabase:disable-transaction migration:
CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_orders_status ON public.orders(status);

For the complete set — two-phase column rename with a sync trigger, safe type change via add-backfill-swap, and an SDK health-check that samples query latency during the migration — see zero-downtime patterns.

Step 3: Data Backfill, Versioning, and Rollback

See data backfill, versioning, and rollback for batch backfill patterns with the SDK, schema versioning across environments, three rollback strategies (compensating migration, repair, feature flags), and type regeneration after migrations.

Output

This skill produces:

  • Migration creation workflownpx supabase migration new with descriptive SQL files and local testing
  • Zero-downtime patterns — safe column additions, two-phase renames, concurrent index creation
  • Batch backfill — SDK-based row-by-row updates with progress logging and rate limiting
  • Schema versioningsupabase migration list and db diff for comparing environments
  • Rollback strategies — compensating migrations, migration repair, and feature-flagged schema changes
  • Type regenerationsupabase gen types typescript after every schema change
  • Migration promotiondb push workflow from local to staging to production

Error Handling

ErrorCauseSolution
migration has already been appliedRe-running existing migrationUse supabase migration list to check status; never modify applied migrations
cannot run inside a transaction blockCREATE INDEX CONCURRENTLY in transactionAdd -- supabase:disable-transaction comment at top of migration file
column does not exist after migrationMigration not applied or types staleRun supabase db push then supabase gen types typescript
deadlock detected during backfillConcurrent updates on same rowsReduce batch size; add retry logic with exponential backoff
statement timeout on large tableMigration takes longer than timeoutIncrease statement_timeout in migration: SET statement_timeout = '300s';
migration repair failedWrong version numberUse exact version from supabase migration list (the timestamp prefix)
db diff shows unexpected changesSchema drift from manual SQL Editor changesRun supabase db pull to capture manual changes as a migration
Type mismatch after migrationGenerated types don't match new schemaDelete database.types.ts and regenerate from --local or --linked

Examples

The create-write-test-push workflow for a real column addition:

npx supabase migration new add_tags_to_projects
cat > supabase/migrations/20260322150000_add_tags_to_projects.sql << 'SQL'
ALTER TABLE public.projects ADD COLUMN tags text[] DEFAULT '{}';
CREATE INDEX idx_projects_tags ON public.projects USING GIN(tags);
SQL
npx supabase db reset
npx supabase gen types typescript --local > lib/database.types.ts
npx supabase link --project-ref <staging-ref> && npx supabase db push

See examples for three full worked examples: the complete local-to-production migration workflow, a batch backfill with progress tracking from the SDK, and a safe enum migration using a CHECK constraint instead of ALTER TYPE.

Resources

Next Steps

  • For advanced troubleshooting after migrations, see supabase-advanced-troubleshooting
  • For multi-environment migration promotion, see supabase-multi-env-setup
  • For performance tuning after schema changes, see supabase-performance-tuning

When not to use it

  • When performing trivial schema changes on small, non-production tables
  • When database locks are acceptable for maintenance windows

Prerequisites

Supabase CLI@supabase/supabase-js v2+Local Supabase instance

Limitations

  • Requires careful handling of transaction blocks for concurrent operations
  • Large table migrations may require statement timeout adjustments

How it compares

It enforces a structured, version-controlled migration lifecycle instead of manual SQL execution in the dashboard.

Compared to similar skills

supabase-migration-deep-dive side by side with the closest alternatives in the catalog.

SkillInstallsUpdatedSafetyDifficulty
supabase-migration-deep-dive (this skill)126dReviewIntermediate
drizzle-orm322moNo flagsIntermediate
database-design66moReviewIntermediate
prisma-expert126moReviewIntermediate

Try saying

Example prompts that trigger this skill in your AI assistant.

More by jeremylongshore

View all by jeremylongshore

analyzing-logs

jeremylongshore

Analyze application logs to detect performance issues, identify error patterns, and improve stability by extracting key insights.

14123

ollama-setup

jeremylongshore

Configure auto-configure Ollama when user needs local LLM deployment, free AI alternatives, or wants to eliminate hosted API costs. Trigger phrases: "install ollama", "local AI", "free LLM", "self-hosted AI", "replace OpenAI", "no API costs". Use when appropriate context detected. Trigger with relevant phrases based on skill purpose.

1167

backtesting-trading-strategies

jeremylongshore

Backtest crypto and traditional trading strategies against historical data. Calculates performance metrics (Sharpe, Sortino, max drawdown), generates equity curves, and optimizes strategy parameters. Use when user wants to test a trading strategy, validate signals, or compare approaches. Trigger with phrases like "backtest strategy", "test trading strategy", "historical performance", "simulate trades", "optimize parameters", or "validate signals".

1071

generating-database-seed-data

jeremylongshore

Process this skill enables AI assistant to generate realistic test data and database seed scripts for development and testing environments. it uses faker libraries to create realistic data, maintains relational integrity, and allows configurable data volumes. u... Use when working with databases or data models. Trigger with phrases like 'database', 'query', or 'schema'.

1033

cursor-codebase-indexing

jeremylongshore

Execute set up and optimize Cursor codebase indexing. Triggers on "cursor index setup", "codebase indexing", "index codebase", "cursor semantic search". Use when working with cursor codebase indexing functionality. Trigger with phrases like "cursor codebase indexing", "cursor indexing", "cursor".

885

testing-mobile-apps

jeremylongshore

Execute mobile app testing on iOS and Android devices/simulators. Use when performing specialized testing. Trigger with phrases like "test mobile app", "run iOS tests", or "validate Android functionality".

810

Search skills

Search the agent skills registry