Supabase migration writer
Skill megandmartin/agent-skills-repo/skills/builder-dev/supabase-migration-writer
Write production-grade Postgres migrations for Supabase — RLS enabled by default, auth.uid() = user_id policies, indexes on every foreign key, comments, timestamped files. Use when the user says "add a table", "write a migration", "schema for", "alter the table", or is shaping Supabase/Postgres data. Don't use for testing the API the table serves — use api-endpoint-tester.From its SKILL.md
npx -y skills add megandmartin/agent-skills-repo --skill supabase-migration-writerAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
2 things to look at
- 22 days oldThe repository was created 22 days ago. New is not bad, but a brand new repository carrying a familiar-sounding name is the shape a typosquat arrives in, and there has been no time for anyone else to find a problem with it.
- 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its file declares
Copied from the file, not written here
The file declares its own license as MIT. That is the author’s claim about this one file, and it is not the same thing as the license GitHub reports for the repository, which is listed with the other numbers below.
SKILL.md
6.7 KB, ~1.5k tokens by cl100k_base, as published. Nobody here has run it
Supabase Migration Writer
Writes migrations the way a senior DBA would: every table gets row-level security ON before it ever holds data, every foreign key gets an index, every object gets a comment, and every file gets a timestamp so migrations run in order forever. A table without RLS on Supabase is a public table — this skill makes that mistake impossible.
When to Use
- Creating or altering tables, columns, indexes, or policies on a Supabase project.
- Turning "the app needs to store X" into runnable SQL.
- Auditing an existing table for missing RLS or indexes.
- Not for: smoke-testing endpoints that read the table — use
api-endpoint-tester. Not for committing/PR-ing the file — hand off togit-ship-flow.
Quick Reference
| Action | Command / Call |
|---|---|
| Timestamped filename | echo "supabase/migrations/$(date -u +%Y%m%d%H%M%S)_add_projects.sql" |
| New migration (CLI) | supabase migration new add_projects |
| Sanity-check SQL syntax | python3 -c "import sys; s=open(sys.argv[1]).read(); assert s.count('(')==s.count(')'), 'unbalanced parens'; print('ok')" <file> |
| Apply locally | supabase db reset (rebuilds local DB from all migrations) |
| Apply to remote | supabase db push (gate behind confirm) |
| Find tables missing RLS | select tablename from pg_tables where schemaname='public' and rowsecurity=false; |
Procedure
- Precheck —
command -v supabase(optional but preferred; without it, deliver the SQL file and apply via the Supabase dashboard SQL editor). Confirm the target: local dev or remote project, and which schema (defaultpublic). - Model — pin down: table name (snake_case, plural), columns + types, which column ties a row to its owner (
user_id uuidreferencingauth.usersin the standard case), and whether rows are per-user private, team-shared, or public-read. - Write the file — timestamped name (table above), then SQL in this exact order: table → comment → indexes →
enable row level security→ policies →comment on policy. Skeleton:
-- 20260724093000_add_projects.sql
create table public.projects (
id uuid primary key default gen_random_uuid(),
user_id uuid not null references auth.users (id) on delete cascade,
name text not null check (char_length(name) between 1 and 120),
created_at timestamptz not null default now(),
updated_at timestamptz not null default now()
);
comment on table public.projects is 'One row per user-created project.';
create index projects_user_id_idx on public.projects (user_id);
alter table public.projects enable row level security;
create policy "owners select own rows" on public.projects
for select to authenticated using ((select auth.uid()) = user_id);
create policy "owners insert own rows" on public.projects
for insert to authenticated with check ((select auth.uid()) = user_id);
create policy "owners update own rows" on public.projects
for update to authenticated using ((select auth.uid()) = user_id)
with check ((select auth.uid()) = user_id);
create policy "owners delete own rows" on public.projects
for delete to authenticated using ((select auth.uid()) = user_id);
Rules baked in: (select auth.uid()) (initplan form — evaluated once per query, not per row); one policy per verb, never for all; to authenticated unless anonymous access is a stated requirement; index every FK and every column policies filter on; destructive DDL (drop, alter ... drop column) goes in its own migration with a header comment naming what data it loses.
4. Lint pass — reread against the checklist: RLS enabled? all four verbs covered (or the omission is intentional and commented)? with check present on insert/update? timestamps timestamptz? FK has on delete behavior chosen deliberately?
5. Apply locally — supabase db reset; success is a clean run with no errors and the table visible via psql/Studio. Prove the policy works: as user A insert a row, as user B select — expect zero rows.
6. Confirm before remote push — supabase db push changes a live database. Show the user the file list and what each does; on destructive changes, restate what's dropped and require an explicit yes plus a fresh backup/branch. Never push destructive DDL to prod as the first application.
Output Template
## Migration Ready
File: supabase/migrations/20260724093000_add_projects.sql
Creates: public.projects (RLS ✅, policies: select/insert/update/delete for owners)
Indexes: projects_user_id_idx
Destructive: none | ⚠️ drops <thing> — data lost: <what>
Applied: local ✅ (db reset clean) | remote: awaiting your confirm
Policy proof: user B cannot read user A's rows ✅
Pitfalls
- Table created, RLS forgotten — on Supabase that table is readable/writable by anyone with the anon key. Recovery: run the rowsecurity query from Quick Reference now; for any hit, ship an immediate migration enabling RLS + policies, then check logs for unexpected access.
- Policy uses bare
auth.uid()in a hot path — works, but re-evaluates per row and tanks big queries. Recovery: rewrite as(select auth.uid()) = user_id; same semantics, one evaluation. for allpolicy hides a missingwith check— users can hand rows to other users on update. Recovery: split into per-verb policies; every insert/update policy gets an explicitwith check.- Editing an already-applied migration file — local and remote histories now disagree and
db pushmisbehaves. Recovery: never edit applied files; write a new migration that alters forward. - Unindexed FK — deletes on the parent table and policy filters go slow at scale. Recovery:
create index concurrentlyon the FK column (run outside a transaction).
Verification
- Filename starts with a UTC timestamp and describes the change
-
alter table ... enable row level securitypresent for every new table - Every policy verb intentional; insert/update have
with check - Every FK and policy-filter column indexed
-
supabase db resetruns clean locally; cross-user read test returns zero rows - No remote push happened without explicit user confirmation
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.