---
name: supabase-schema-designer
description: Design a Supabase/Postgres schema — tables, keys, relations, indexes, row-level security (RLS) policies per role, triggers, storage bucket policies, and versioned SQL migrations with seed data. Use for Supabase backends, database design for an app, or 'set up the tables and policies for…'.
license: Proprietary — Lendskill original
---
# Supabase Schema Designer
## 1. Model
Entities and relationships from the app spec. Tables: `id uuid primary key default gen_random_uuid()`, `created_at timestamptz default now()`, owner column `user_id uuid references auth.users not null` where rows belong to a user. Foreign keys with explicit `on delete` behavior. Index every foreign key and common filter.
## 2. RLS — on for every table in exposed schemas
```sql
alter table public.notes enable row level security;
create policy "own notes: select" on public.notes for select using ((select auth.uid()) = user_id);
create policy "own notes: insert" on public.notes for insert with check ((select auth.uid()) = user_id);
```
Separate policies per action. Team access through a membership table checked in policies (via a `security definer` function with a fixed `search_path` if needed). Never expose the service-role key to clients.
## 3. Extras
`updated_at` triggers, check constraints for enums/ranges, storage bucket policies by path prefix (`auth.uid()::text`).
## 4. Migrations
Numbered SQL migration files (`supabase migration new …`), a `seed.sql`, and test queries run as two different users proving each can only see their own rows. Run the project's security advisor if available.
## Output format
- SQL migration: tables, keys, indexes and constraints
- Row-level security policies per table with what each allows
- An ER diagram (Mermaid) and example queries