new-migration
Create a Supabase migration with RLS, indexes and pgTAP tests. Use for any table, column, policy, trigger or RPC change.
SKILL.md.claude/skills/new-migration/SKILL.md
GitHubCreate the migration $ARGUMENTS.
- Read
docs/06-data-model.mdfor the entity and its invariants, anddocs/07-supabase-schema.md§4–§5 for the RLS and trigger patterns. pnpm db:new $ARGUMENTSto create the timestamped file.- In the same file:
- the DDL, with check constraints for every invariant that can be expressed in the database
alter table … enable row level security- all four policies (select/insert/update/delete) using
app.can_read/app.is_member - indexes for every query pattern the feature needs
- triggers (
touch_updated_at,freeze_householdwhere applicable)
- Add a pgTAP test in
supabase/tests/proving: user A cannot read user B's rows; apersonal-scoped row is invisible to another household member; every check constraint rejects bad data. - Update the drizzle schema in
src/db/schema.tsif the table is mirrored locally. - Run
pnpm db:reset && pnpm test:db.
The migration must be backward compatible with the currently released app (expand → migrate → contract across two releases). Never drop a column in the same release that stops writing it.