# "Supabase Cursor 10X Database Workflow AI" <!-- ref: @content/youtube/yifan-bth/2025-03-27-supabase-cursor-10x-database-workflow-ai version: 4 updated_at: 2026-10-31T21:11:06.222Z --> From Yifan BTH, 2025-03-27: Supabase's CLI exposes a code-first migration, type-generation, and seed workflow that AI agents can drive end-to-end through a shared rules file and the Postgres MCP. A solo walkthrough by yifan-bth on how to combine Supabase's Postgres tooling with AI coding agents (Cursor, Windsurf, Copilot, Cline) to compress database management work from hours to minutes. ## Core Thesis Supabase's CLI exposes a code-first migration, type-generation, and seed workflow that AI agents can drive end-to-end through a shared rules file and the Postgres MCP. By committing migrations + generated TypeScript types + seed SQL to the repo, the database becomes fully reproducible — letting developers ship Postgres-backed features with the speed previously reserved for NoSQL prototypes, without giving up schema rigor or production safety. ## Key Insights - **Supabase is a utility layer over Postgres**, not just a wrapper — its local CLI replicates ~99% of production behavior via Docker, enabling safe local reproduction of prod. - **Migrations are the linchpin** of healthy SQL workflows. Mishandled migrations (especially destructive `DROP`s) are the fastest path to taking down production. - **AI agents can run the full migration loop autonomously**: read schema → generate migration via CLI → apply locally → regenerate TypeScript types → self-correct on errors (e.g., switching to `CREATE OR REPLACE VIEW`). - **Generated TypeScript types are the killer feature** — they catch AI-generated schema mismatches at compile time, so untested code paths don't reach prod. - **Symlink one canonical `rules.md`** across Cursor/Windsurf/Copilot/Cline to avoid editor lock-in and behavior drift as the AI editor war heats up. - **Use the Postgres MCP**, not a Supabase-specific MCP — Supabase's own docs recommend it, since Postgres is what runs underneath. - **Strict separation of migrations vs. seed data**: schema changes live in migrations; data lives in `seed.sql`. `supabase db reset` replays both for deterministic state. - **Enforce invariants at the DB layer, not application code** — e.g., `created_at` / `updated_at` columns wired to Postgres trigger functions so timestamps survive any client. - **Backwards-incompatible migrations are the #1 rookie mistake.** Correct order: remove application logic → soak period → drop column. - **RLS is deny-by-default and reads fail silently.** Once enabled, missing data on the client surfaces as empty results, not 401/403 — a major debugging trap, but intentional to prevent existence inference. - **Free tier suffices for hundreds of users**; paid tier is mainly justified by 7-day backup retention. ## Actionable Takeaways 1. Run `supabase start` to spin up the local Docker stack; develop and test exclusively against local — never prod — once real customers exist. 2. Symlink one `rules.md` across all AI editor rules files (`.cursor/rules`, Windsurf, Copilot, Cline). 3. Encode these rules for the AI: use Supabase CLI for migrations, read the generated types file first, apply migrations and regenerate types after each change, default new tables to `created_at`/`updated_at` with triggers, **enable RLS on every new table**, and **never make backwards-incompatible changes**. 4. Auto-approve migrations locally to preserve flow; require manual review in production, especially around `DROP`. 5. Capture any UI-driven schema changes with `supabase db diff -f <filename>` — but prefer writing migrations directly, since UI edits can miss subtle details. 6. Configure the Postgres MCP with a connection URL; commit local-dev creds, but use env-var loading for production secrets. 7. Generate seed data from a working local DB: `npx supabase db dump --data-only --local -f seed.sql`. Never seed from prod data. 8. Run `supabase db reset` regularly — if it breaks things, your DB has un-versioned drift. 9. Use Supabase CLI inside GitHub Actions for CI; use database branching so each PR gets its own snapshot. 10. Deploy migrations to production with `supabase db push`. 11. When debugging missing data, suspect RLS before suspecting the query — reads fail silently. ## Notable Quotes > "To say it's a wrapper is probably underplaying its importance." > "Don't do that in prod. God, please do not do that in prod." > "Managing migrations is the key to making great Postgres or just generally SQL workflows." > "This AI code editor war is just heating up. Everyone is racing to release new features all the time." > "Everything is actually versioned inside code, it didn't even need to read the database to actually implement this feature correctly." > "The migration should just be about your data structure changes but never about the data changes themselves." > "Never make any backwards breaking changes... this is a common rookie mistake." > "When you turn on role level security, it means that by default, no one has access to anything." > "RLS is specifically designed in way that users cannot use queries to determine if the data's exist or not." > "Once you've done the AI setup you probably don't need to touch any SQL during your feature coding sessions." --- *You're reading a protocol on [protocol.supply](https://protocol.supply) — hosted, searchable knowledge for AI agents. Think Agent Skills, as an API: bootstrap once (`curl -sL https://api.protocol.supply/bootstrap`), search (`/search?q=…`), fetch (`/@repo/slug`).* *Any skill can become a protocol, and any protocol installs as a local skill — tell your agent "install this as a skill" or see [`@protocol/protocol-to-skill`](https://api.protocol.supply/@protocol/protocol-to-skill).*