Claude Templates / C-tier · Discipline
Discipline
The Supabase Migration Playbook
Migration discipline: numbering, guards, application, and the never-destructive rule.
SUPABASE-MIGRATION-PLAYBOOK.md · 14 sections · 1,767 words · 14 KB · markdown
By Moe Ameen, founder of BILT · Published · Updated
The Supabase Migration Playbook sets the rules for changing a production Postgres schema with Claude Code: strictly sequenced migration files, IF NOT EXISTS guards so a rerun does nothing, applying through the Management API or Supabase MCP, a tracking doc of what's applied, pending or skipped, row-level security on every table, and a hard rule never to run destructive changes on user-owned data.
Key takeaways
- Number migration files in strict sequence.
- Every migration must be safe to run twice.
- Track applied, pending and skipped migrations in one doc.
- Never delete user-owned data in a migration or sync.
How to change a production schema without losing data. Sequential numbering, IF NOT EXISTS guards so a re-run is a no-op, applying via the Management API, tracking what's actually been applied, and the hard rule that sync routines never delete.
What does the Supabase Migration Playbook set up?
It sets up the migrations folder, the naming convention, the apply workflow (write, review, apply, record, never re-apply) and an approval and backup step.
It also lists schema patterns that age well and common pitfalls.
When should you use it?
Use it on every migration, every time. The file's own when-to-use line is exactly that.
It matters most once real users exist, because a bad migration then costs data.
What do you need first?
You need App Infrastructure, your Supabase project ref and a personal access token (not the anon or service-role keys).
Pick a file path for the applied-migration tracking doc so it survives across sessions.
What's inside
What does the playbook give you?
- //Numbering and file-naming convention
- //IF NOT EXISTS guards that make every migration re-runnable
- //Applying migrations via the Management API
- //An applied-migration tracking doc pattern
- //The never-destructive rule and the incident that produced it
- //PostgREST gotchas: float-to-int coercion, the 1000-row cap
When to use it
Every migration. Every time.
Build these first
Straight from the file
What does the writing look like?
Every migration must be safe to re-apply against a DB where it has already run. Real-world reason: applied-state tracking drifts; you WILL re-run a migration by accident; the migration must no-op gracefully instead of crashing.
Table of contents
Which sections does the file cover?
- 0. Use this spec
- 1. File naming convention (load-bearing)
- 2. Idempotency is mandatory
- 3. Application: how to actually run a migration
- 4. Applied-migration tracking
- Applied
- Pending (in repo, not yet live)
- Skipped (intentionally not applied)
- 5. RLS hygiene — non-negotiable
- 6. Never destructive on user-owned data
- 7. Schema patterns that age well
- 8. Approval + backup workflow
- 9. Common pitfalls
- 10. Kickoff prompt
How do you run it?
Drop SUPABASE-MIGRATION-PLAYBOOK.md into your repo, then tell Claude Code: “Read SUPABASE-MIGRATION-PLAYBOOK.md and implement it in this codebase.” It's written for an agent to execute end to end. Search the file for angle-bracket placeholders and swap in your own project names, domains, and keys before the first run.
Who is this for, and who should skip it?
Best for
- Apps on Supabase with real user data
- Developers letting an AI agent write schema changes
- Teams that lost track of which migrations ran
Not ideal for
- Projects on other databases or ORMs with their own migration tools
- Throwaway prototypes
- Teams already enforcing reviewed migrations in CI
- Builders who won't adapt paths: the file points to a reference app you won't have
What else do people ask?
Why does the Supabase Migration Playbook ban supabase db push?
The Supabase Migration Playbook says migrations applied through the dashboard, the Management API or the Supabase MCP don't populate migration_history. On a project like that, supabase db push tries to re-apply every migration and the non-idempotent ones crash.
What if a migration can't be made idempotent?
The Supabase Migration Playbook wraps it, usually a data backfill, in a DO block that checks for a sentinel row in schema_migrations_local. The backfill runs and records its name only when the sentinel is missing.
Should status columns use Postgres ENUMs?
The Supabase Migration Playbook prefers CHECK constraints for status fields. It says ENUMs need a drop-and-recreate or an add-value that can't be undone, and they break PostgREST type generation in subtle ways.
Does it work outside Supabase?
The Supabase Migration Playbook assumes Supabase: it applies migrations through the Supabase MCP, the Management API or the dashboard SQL editor, and its RLS policies use auth.uid(). Projects on other databases, or ORMs with their own migration tools, are a poor fit.
What is in the Supabase Migration Playbook download?
The Supabase Migration Playbook is a markdown file of about 1,800 words. It includes SQL guard examples for tables, columns, indexes, triggers, policies and enums, a sentinel-guarded backfill, a curl call to the Management API and a markdown template for tracking applied migrations.
How do we know this?
This page is based on the playbook file itself, SUPABASE-MIGRATION-PLAYBOOK.md, which Moe Ameen wrote from the Kompozy codebase (called BKE in the file). We read the file on November 4, 2026; the facts here come from it, not from independent testing in other codebases.
More discipline playbooks
Pre-Production Hardening
The last pass before public traffic: secrets, RLS, headers, limits, legal.
Read + download →C-tierCore Web Vitals Audit
LCP, CLS, INP: measure it properly, then fix the things that actually move it.
Read + download →C-tierAI Compliance Gate
Brand safety for AI-generated output: banned words, anti-tells, injection defense.
Read + download →