[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M796HS6S44AGFRDZTRYX836S":3,"skill-same:01M796HS6S44AGFRDZTRYX836S":60},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":37,"commitSha":38,"skillDirectory":39,"forksCount":40,"repositoryHtmlUrl":41,"repositoryHomepageUrl":6,"ownerHtmlUrl":42,"ownerBlogUrl":43,"ownerDescription":44,"updatedAt":45,"install":46,"resources":59},"01M796HS6S44AGFRDZTRYX836S","supabase-schema-from-requirements",null,"Design Supabase Postgres schema from business requirements with migrations, RLS, and types.\nUse when translating specifications into database tables, creating migration files,\nadding Row Level Security policies, or generating TypeScript types from schema.\nTrigger with phrases like \"supabase schema\", \"design database supabase\",\n\"schema from requirements\", \"supabase migration\", \"supabase tables from spec\".","jukeyman\u002Fjukeyman-skills","jukeyman","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F142960420?v=4","01M78FR4Y3DHMMCBCC0GXXNB3F","RICK JEFFERSON","01M78FR4Z8RVQRAD31Y5J7V6EB",1,"MIT","https:\u002F\u002Fgithub.com\u002Fjukeyman\u002Fjukeyman-skills\u002Fblob\u002Fmain\u002Fskills\u002Fsaas-packs--supabase-pack--supabase-schema-from-requirements\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: supabase-schema-from-requirements\ndescription: |\n  Design Supabase Postgres schema from business requirements with migrations, RLS, and types.\n  Use when translating specifications into database tables, creating migration files,\n  adding Row Level Security policies, or generating TypeScript types from schema.\n  Trigger with phrases like \"supabase schema\", \"design database supabase\",\n  \"schema from requirements\", \"supabase migration\", \"supabase tables from spec\".\nallowed-tools: Read, Write, Edit, Bash(supabase:*), Bash(npx:*), Grep\nversion: 1.0.0\nlicense: MIT\nauthor: Jeremy Longshore \u003Cjeremy@intentsolutions.io>\ncompatible-with: claude-code, codex, openclaw\ntags: [saas, supabase, database, migration, schema-design, postgres, rls]\n---\n# Supabase Schema from Requirements\n\n## Overview\n\nTranslate business requirements into a production-ready Postgres schema inside Supabase. This skill covers the full path from specification document to applied migration: entity extraction, table creation with proper data types and constraints, Row Level Security policies, performance indexes, timestamp triggers, and TypeScript type generation. It is the highest-leverage activity in the early stages of any Supabase project because every downstream feature (auth, storage, realtime, edge functions) depends on well-designed tables.\n\n## Prerequisites\n\n- Supabase CLI installed (`npm install -g supabase`) and project linked (`supabase link`)\n- `@supabase\u002Fsupabase-js` v2+ installed in the project\n- Business requirements, PRD, or specification document identifying entities and access rules\n- Local Supabase running (`supabase start`) or a linked remote project\n\n## Instructions\n\n### Step 1: Parse Requirements and Create Migration\n\nRead the requirements document and extract entities, attributes, relationships, and access control rules. Map each entity to a Postgres table.\n\n**Entity extraction example** (project management app):\n\n| Entity | Key Columns | Relationships |\n|--------|------------|---------------|\n| Organization | name, slug, plan | has many Projects, has many Members |\n| Project | name, description, status | belongs to Organization, has many Tasks |\n| Task | title, priority, status, due_date | belongs to Project, assigned to User |\n| Member | role (owner\u002Fadmin\u002Fmember) | junction linking User to Organization |\n\nCreate the migration file:\n\n```bash\nnpx supabase migration new create_tables\n# Creates: supabase\u002Fmigrations\u002F\u003Ctimestamp>_create_tables.sql\n```\n\nWrite the migration SQL using standard Postgres data types (`uuid`, `text`, `integer`, `boolean`, `timestamptz`, `jsonb`):\n\n```sql\n-- supabase\u002Fmigrations\u002F\u003Ctimestamp>_create_tables.sql\n\n-- Enable required extensions\ncreate extension if not exists \"uuid-ossp\";\ncreate extension if not exists \"moddatetime\";\n\n-- Organizations\ncreate table public.organizations (\n  id uuid default uuid_generate_v4() primary key,\n  name text not null,\n  slug text unique not null,\n  plan text default 'free' check (plan in ('free', 'pro', 'enterprise')),\n  metadata jsonb default '{}'::jsonb,\n  created_at timestamptz default now() not null,\n  updated_at timestamptz default now() not null\n);\n\n-- Organization members (junction table)\ncreate table public.members (\n  id uuid default uuid_generate_v4() primary key,\n  organization_id uuid references public.organizations(id) on delete cascade not null,\n  user_id uuid references auth.users(id) on delete cascade not null,\n  role text default 'member' check (role in ('owner', 'admin', 'member')),\n  created_at timestamptz default now() not null,\n  unique (organization_id, user_id)\n);\n\n-- Projects\ncreate table public.projects (\n  id uuid default uuid_generate_v4() primary key,\n  organization_id uuid references public.organizations(id) on delete cascade not null,\n  name text not null,\n  description text,\n  status text default 'active' check (status in ('active', 'archived', 'deleted')),\n  settings jsonb default '{}'::jsonb,\n  created_at timestamptz default now() not null,\n  updated_at timestamptz default now() not null\n);\n\n-- Tasks\ncreate table public.tasks (\n  id uuid default uuid_generate_v4() primary key,\n  project_id uuid references public.projects(id) on delete cascade not null,\n  assigned_to uuid references auth.users(id) on delete set null,\n  title text not null,\n  description text,\n  priority integer default 0 check (priority between 0 and 4),\n  status text default 'todo' check (status in ('todo', 'in_progress', 'done', 'cancelled')),\n  due_date date,\n  tags text[] default '{}',\n  created_at timestamptz default now() not null,\n  updated_at timestamptz default now() not null\n);\n\n-- Indexes for common query patterns\ncreate index idx_members_user on public.members(user_id);\ncreate index idx_members_org on public.members(organization_id);\ncreate index idx_projects_org on public.projects(organization_id);\ncreate index idx_tasks_project on public.tasks(project_id);\ncreate index idx_tasks_assigned on public.tasks(assigned_to);\ncreate index idx_tasks_status on public.tasks(status) where status not in ('done', 'cancelled');\ncreate index idx_tasks_due on public.tasks(due_date) where due_date is not null;\ncreate index idx_orgs_slug on public.organizations(slug);\n\n-- Automatic updated_at triggers via moddatetime extension\ncreate trigger handle_updated_at before update on public.organizations\n  for each row execute procedure moddatetime(updated_at);\ncreate trigger handle_updated_at before update on public.projects\n  for each row execute procedure moddatetime(updated_at);\ncreate trigger handle_updated_at before update on public.tasks\n  for each row execute procedure moddatetime(updated_at);\n```\n\n**Data type selection guide:**\n\n| Use case | Type | Notes |\n|----------|------|-------|\n| Primary keys | `uuid` | Always with `uuid_generate_v4()` default |\n| Names, titles | `text` | Prefer over `varchar` in Postgres |\n| Counts, ranks | `integer` | Use `bigint` for sequences |\n| Flags | `boolean` | Default explicitly to `true` or `false` |\n| Timestamps | `timestamptz` | Never use `timestamp` without timezone |\n| Flexible data | `jsonb` | Queryable JSON; use for settings, metadata |\n| Lists | `text[]` | Postgres arrays for simple tags or labels |\n\n### Step 2: Add Row Level Security Policies\n\nEvery table exposed to the client must have RLS enabled. Write helper functions first to avoid repeating authorization logic across policies.\n\n```sql\n-- Helper: check if user is a member of an organization\ncreate or replace function public.is_org_member(org_id uuid)\nreturns boolean as $$\n  select exists (\n    select 1 from public.members\n    where organization_id = org_id\n    and user_id = auth.uid()\n  );\n$$ language sql security definer stable;\n\n-- Helper: check if user is org admin or owner\ncreate or replace function public.is_org_admin(org_id uuid)\nreturns boolean as $$\n  select exists (\n    select 1 from public.members\n    where organization_id = org_id\n    and user_id = auth.uid()\n    and role in ('owner', 'admin')\n  );\n$$ language sql security definer stable;\n\n-- Organizations RLS\nalter table public.organizations enable row level security;\n\ncreate policy \"Users read own orgs\"\n  on public.organizations for select\n  using (public.is_org_member(id));\n\ncreate policy \"Authenticated users create orgs\"\n  on public.organizations for insert\n  with check (auth.uid() is not null);\n\ncreate policy \"Admins update orgs\"\n  on public.organizations for update\n  using (public.is_org_admin(id));\n\ncreate policy \"Owners delete orgs\"\n  on public.organizations for delete\n  using (\n    exists (\n      select 1 from public.members\n      where organization_id = id\n      and user_id = auth.uid()\n      and role = 'owner'\n    )\n  );\n\n-- Members RLS\nalter table public.members enable row level security;\n\ncreate policy \"Members view org roster\"\n  on public.members for select\n  using (public.is_org_member(organization_id));\n\ncreate policy \"Admins manage members\"\n  on public.members for all\n  using (public.is_org_admin(organization_id));\n\n-- Projects RLS\nalter table public.projects enable row level security;\n\ncreate policy \"Members view projects\"\n  on public.projects for select\n  using (public.is_org_member(organization_id));\n\ncreate policy \"Admins manage projects\"\n  on public.projects for all\n  using (public.is_org_admin(organization_id));\n\n-- Tasks RLS\nalter table public.tasks enable row level security;\n\ncreate policy \"Members view tasks\"\n  on public.tasks for select\n  using (\n    exists (\n      select 1 from public.projects p\n      where p.id = project_id\n      and public.is_org_member(p.organization_id)\n    )\n  );\n\ncreate policy \"Members create tasks\"\n  on public.tasks for insert\n  with check (\n    exists (\n      select 1 from public.projects p\n      where p.id = project_id\n      and public.is_org_member(p.organization_id)\n    )\n  );\n\ncreate policy \"Assignee or admin updates tasks\"\n  on public.tasks for update\n  using (\n    assigned_to = auth.uid()\n    or exists (\n      select 1 from public.projects p\n      where p.id = project_id\n      and public.is_org_admin(p.organization_id)\n    )\n  );\n```\n\n**RLS policy naming convention:** Use short, descriptive names that state who and what action: `\"Users read own\"`, `\"Admins manage members\"`, `\"Assignee updates tasks\"`.\n\n### Step 3: Apply Migration and Generate Types\n\n```bash\n# Apply migration locally\nnpx supabase db reset\n\n# Or push to a linked remote project\nnpx supabase db push\n\n# Generate TypeScript types from the live schema\nnpx supabase gen types typescript --local > types\u002Fsupabase.ts\n```\n\nUse the generated types with the Supabase client:\n\n```typescript\nimport { createClient } from '@supabase\u002Fsupabase-js'\nimport type { Database } from '.\u002Ftypes\u002Fsupabase'\n\nconst supabase = createClient\u003CDatabase>(\n  process.env.NEXT_PUBLIC_SUPABASE_URL!,\n  process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!\n)\n\n\u002F\u002F Typed insert\nconst { data: org, error } = await supabase\n  .from('organizations')\n  .insert({ name: 'Acme Corp', slug: 'acme', plan: 'pro' })\n  .select()\n  .single()\n\n\u002F\u002F Typed select with foreign key join\nconst { data: tasks } = await supabase\n  .from('tasks')\n  .select('*, project:project_id(name, organization_id)')\n  .eq('status', 'todo')\n  .order('due_date', { ascending: true })\n\n\u002F\u002F Nested join across multiple tables\nconst { data: orgWithProjects } = await supabase\n  .from('organizations')\n  .select(`\n    id, name, slug,\n    projects:projects(\n      id, name, status,\n      tasks:tasks(id, title, status, assigned_to)\n    )\n  `)\n  .eq('slug', 'acme')\n  .single()\n```\n\nVerify RLS is working:\n\n```typescript\n\u002F\u002F This should return only rows the authenticated user can see\nconst { data, error } = await supabase.from('organizations').select('*')\n\nif (error) {\n  console.error('RLS check failed:', error.message)\n}\nconsole.log(`User can see ${data?.length ?? 0} organizations`)\n```\n\n## Output\n\n- SQL migration file under `supabase\u002Fmigrations\u002F` with all tables, constraints, and indexes\n- RLS policies matching the access control rules from requirements\n- Helper functions (`is_org_member`, `is_org_admin`) for reusable authorization checks\n- `moddatetime` triggers for automatic `updated_at` management\n- Generated TypeScript types at `types\u002Fsupabase.ts` for type-safe client queries\n- Partial indexes on frequently filtered columns (status, due_date)\n\n## Error Handling\n\n| Error | Cause | Solution |\n|-------|-------|----------|\n| `42P07: relation already exists` | Table name collision in migration | Use `create table if not exists` or rename the table |\n| `23503: foreign key violation` | Insert references a nonexistent parent row | Insert parent rows first, or check the UUID |\n| `42501: insufficient privilege` | RLS helper function permissions | Add `security definer` to the function definition |\n| `42883: function uuid_generate_v4() does not exist` | Extension not enabled | Add `create extension if not exists \"uuid-ossp\"` |\n| `supabase db push` succeeds but tables missing | Migration was already recorded | Check `supabase_migrations.schema_migrations` and repair |\n| `PGRST204: column not found` | TypeScript types out of sync | Re-run `npx supabase gen types typescript --local > types\u002Fsupabase.ts` |\n| `new row violates row-level security` | RLS policy blocks the operation | Verify `auth.uid()` matches expected value; check policy `using` clause |\n| `moddatetime` trigger fails | Extension not enabled | Add `create extension if not exists \"moddatetime\"` at top of migration |\n\n## Examples\n\n**E-commerce schema** (different domain, same pattern):\n\n```sql\ncreate table public.products (\n  id uuid default uuid_generate_v4() primary key,\n  store_id uuid references public.stores(id) on delete cascade not null,\n  name text not null,\n  price integer not null check (price >= 0),  -- cents\n  currency text default 'usd',\n  inventory integer default 0 check (inventory >= 0),\n  metadata jsonb default '{}'::jsonb,\n  is_active boolean default true,\n  created_at timestamptz default now() not null,\n  updated_at timestamptz default now() not null\n);\n\nalter table public.products enable row level security;\n\ncreate policy \"Anyone reads active products\"\n  on public.products for select\n  using (is_active = true);\n\ncreate policy \"Store owners manage products\"\n  on public.products for all\n  using (\n    exists (\n      select 1 from public.stores s\n      where s.id = store_id and s.owner_id = auth.uid()\n    )\n  );\n\ncreate trigger handle_updated_at before update on public.products\n  for each row execute procedure moddatetime(updated_at);\n```\n\n**Querying the e-commerce schema from the client:**\n\n```typescript\n\u002F\u002F Products with store info\nconst { data: products } = await supabase\n  .from('products')\n  .select('*, store:store_id(name, slug)')\n  .eq('is_active', true)\n  .gte('inventory', 1)\n  .order('price', { ascending: true })\n  .limit(20)\n```\n\n## Resources\n\n- [Row Level Security Guide](https:\u002F\u002Fsupabase.com\u002Fdocs\u002Fguides\u002Fdatabase\u002Fpostgres\u002Frow-level-security)\n- [Database Migrations](https:\u002F\u002Fsupabase.com\u002Fdocs\u002Fguides\u002Fdeployment\u002Fdatabase-migrations)\n- [Supabase CLI Reference](https:\u002F\u002Fsupabase.com\u002Fdocs\u002Freference\u002Fcli)\n- [JavaScript Client — Select](https:\u002F\u002Fsupabase.com\u002Fdocs\u002Freference\u002Fjavascript\u002Fselect)\n- [TypeScript Support](https:\u002F\u002Fsupabase.com\u002Fdocs\u002Fguides\u002Fapi\u002Frest\u002Fgenerating-types)\n- [PostgreSQL Data Types](https:\u002F\u002Fwww.postgresql.org\u002Fdocs\u002Fcurrent\u002Fdatatype.html)\n\n## Next Steps\n\nFor auth integration, file storage, and realtime subscriptions on top of this schema, proceed to `supabase-auth-storage-realtime-core`.\n","# Supabase Schema from Requirements\n\n## Overview\n\nTranslate business requirements into a production-ready Postgres schema inside Supabase. This skill covers the full path from specification document to applied migration: entity extraction, table creation with proper data types and constraints, Row Level Security policies, performance indexes, timestamp triggers, and TypeScript type generation. It is the highest-leverage activity in the early stages of any Supabase project because every downstream feature (auth, storage, realtime, edge functions) depends on well-designed tables.\n\n## Prerequisites\n\n- Supabase CLI installed (`npm install -g supabase`) and project linked (`supabase link`)\n- `@supabase\u002Fsupabase-js` v2+ installed in the project\n- Business requirements, PRD, or specification document identifying entities and access rules\n- Local Supabase running (`supabase start`) or a linked remote project\n\n## Instructions\n\n### Step 1: Parse Requirements and Create Migration\n\nRead the requirements document and extract entities, attributes, relationships, and access control rules. Map each entity to a Postgres table.\n\n**Entity extraction example** (project management app):\n\n| Entity | Key Columns | Relationships |\n|--------|------------|---------------|\n| Organization | name, slug, plan | has many Projects, has many Members |\n| Project | name, description, status | belongs to Organization, has many Tasks |\n| Task | title, priority, status, due_date | belongs to Project, assigned to User |\n| Member | role (owner\u002Fadmin\u002Fmember) | junction linking User to Organization |\n\nCreate the migration file:\n\n```bash\nnpx supabase migration new create_tables\n# Creates: supabase\u002Fmigrations\u002F\u003Ctimestamp>_create_tables.sql\n```\n\nWrite the migration SQL using standard Postgres data types (`uuid`, `text`, `integer`, `boolean`, `timestamptz`, `jsonb`):\n\n```sql\n-- supabase\u002Fmigrations\u002F\u003Ctimestamp>_create_tables.sql\n\n-- Enable required extensions\ncreate extension if not exists \"uuid-ossp\";\ncreate extension if not exists \"moddatetime\";\n\n-- Organizations\ncreate table public.organizations (\n  id uuid default uuid_generate_v4() primary key,\n  name text not null,\n  slug text unique not null,\n  plan text default 'free' check (plan in ('free', 'pro', 'enterprise')),\n  metadata jsonb default '{}'::jsonb,\n  created_at timestamptz default now() not null,\n  updated_at timestamptz default now() not null\n);\n\n-- Organization members (junction table)\ncreate table public.members (\n  id uuid default uuid_generate_v4() primary key,\n  organization_id uuid references public.organizations(id) on delete cascade not null,\n  user_id uuid references auth.users(id) on delete cascade not null,\n  role text default 'member' check (role in ('owner', 'admin', 'member')),\n  created_at timestamptz default now() not null,\n  unique (organization_id, user_id)\n);\n\n-- Projects\ncreate table public.projects (\n  id uuid default uuid_generate_v4() primary key,\n  organization_id uuid references public.organizations(id) on delete cascade not null,\n  name text not null,\n  description text,\n  status text default 'active' check (status in ('active', 'archived', 'deleted')),\n  settings jsonb default '{}'::jsonb,\n  created_at timestamptz default now() not null,\n  updated_at timestamptz default now() not null\n);\n\n-- Tasks\ncreate table public.tasks (\n  id uuid default uuid_generate_v4() primary key,\n  project_id uuid references public.projects(id) on delete cascade not null,\n  assigned_to uuid references auth.users(id) on delete set null,\n  title text not null,\n  description text,\n  priority integer default 0 check (priority between 0 and 4),\n  status text default 'todo' check (status in ('todo', 'in_progress', 'done', 'cancelled')),\n  due_date date,\n  tags text[] default '{}',\n  created_at timestamptz default now() not null,\n  updated_at timestamptz default now() not null\n);\n\n-- Indexes for common query patterns\ncreate index idx_members_user on public.members(user_id);\ncreate index idx_members_org on public.members(organization_id);\ncreate index idx_projects_org on public.projects(organization_id);\ncreate index idx_tasks_project on public.tasks(project_id);\ncreate index idx_tasks_assigned on public.tasks(assigned_to);\ncreate index idx_tasks_status on public.tasks(status) where status not in ('done', 'cancelled');\ncreate index idx_tasks_due on public.tasks(due_date) where due_date is not null;\ncreate index idx_orgs_slug on public.organizations(slug);\n\n-- Automatic updated_at triggers via moddatetime extension\ncreate trigger handle_updated_at before update on public.organizations\n  for each row execute procedure moddatetime(updated_at);\ncreate trigger handle_updated_at before update on public.projects\n  for each row execute procedure moddatetime(updated_at);\ncreate trigger handle_updated_at before update on public.tasks\n  for each row execute procedure moddatetime(updated_at);\n```\n\n**Data type selection guide:**\n\n| Use case | Type | Notes |\n|----------|------|-------|\n| Primary keys | `uuid` | Always with `uuid_generate_v4()` default |\n| Names, titles | `text` | Prefer over `varchar` in Postgres |\n| Counts, ranks | `integer` | Use `bigint` for sequences |\n| Flags | `boolean` | Default explicitly to `true` or `false` |\n| Timestamps | `timestamptz` | Never use `timestamp` without timezone |\n| Flexible data | `jsonb` | Queryable JSON; use for settings, metadata |\n| Lists | `text[]` | Postgres arrays for simple tags or labels |\n\n### Step 2: Add Row Level Security Policies\n\nEvery table exposed to the client must have RLS enabled. Write helper functions first to avoid repeating authorization logic across policies.\n\n```sql\n-- Helper: check if user is a member of an organization\ncreate or replace function public.is_org_member(org_id uuid)\nreturns boolean as $$\n  select exists (\n    select 1 from public.members\n    where organization_id = org_id\n    and user_id = auth.uid()\n  );\n$$ language sql security definer stable;\n\n-- Helper: check if user is org admin or owner\ncreate or replace function public.is_org_admin(org_id uuid)\nreturns boolean as $$\n  select exists (\n    select 1 from public.members\n    where organization_id = org_id\n    and user_id = auth.uid()\n    and role in ('owner', 'admin')\n  );\n$$ language sql security definer stable;\n\n-- Organizations RLS\nalter table public.organizations enable row level security;\n\ncreate policy \"Users read own orgs\"\n  on public.organizations for select\n  using (public.is_org_member(id));\n\ncreate policy \"Authenticated users create orgs\"\n  on public.organizations for insert\n  with check (auth.uid() is not null);\n\ncreate policy \"Admins update orgs\"\n  on public.organizations for update\n  using (public.is_org_admin(id));\n\ncreate policy \"Owners delete orgs\"\n  on public.organizations for delete\n  using (\n    exists (\n      select 1 from public.members\n      where organization_id = id\n      and user_id = auth.uid()\n      and role = 'owner'\n    )\n  );\n\n-- Members RLS\nalter table public.members enable row level security;\n\ncreate policy \"Members view org roster\"\n  on public.members for select\n  using (public.is_org_member(organization_id));\n\ncreate policy \"Admins manage members\"\n  on public.members for all\n  using (public.is_org_admin(organization_id));\n\n-- Projects RLS\nalter table public.projects enable row level security;\n\ncreate policy \"Members view projects\"\n  on public.projects for select\n  using (public.is_org_member(organization_id));\n\ncreate policy \"Admins manage projects\"\n  on public.projects for all\n  using (public.is_org_admin(organization_id));\n\n-- Tasks RLS\nalter table public.tasks enable row level security;\n\ncreate policy \"Members view tasks\"\n  on public.tasks for select\n  using (\n    exists (\n      select 1 from public.projects p\n      where p.id = project_id\n      and public.is_org_member(p.organization_id)\n    )\n  );\n\ncreate policy \"Members create tasks\"\n  on public.tasks for insert\n  with check (\n    exists (\n      select 1 from public.projects p\n      where p.id = project_id\n      and public.is_org_member(p.organization_id)\n    )\n  );\n\ncreate policy \"Assignee or admin updates tasks\"\n  on public.tasks for update\n  using (\n    assigned_to = auth.uid()\n    or exists (\n      select 1 from public.projects p\n      where p.id = project_id\n      and public.is_org_admin(p.organization_id)\n    )\n  );\n```\n\n**RLS policy naming convention:** Use short, descriptive names that state who and what action: `\"Users read own\"`, `\"Admins manage members\"`, `\"Assignee updates tasks\"`.\n\n### Step 3: Apply Migration and Generate Types\n\n```bash\n# Apply migration locally\nnpx supabase db reset\n\n# Or push to a linked remote project\nnpx supabase db push\n\n# Generate TypeScript types from the live schema\nnpx supabase gen types typescript --local > types\u002Fsupabase.ts\n```\n\nUse the generated types with the Supabase client:\n\n```typescript\nimport { createClient } from '@supabase\u002Fsupabase-js'\nimport type { Database } from '.\u002Ftypes\u002Fsupabase'\n\nconst supabase = createClient\u003CDatabase>(\n  process.env.NEXT_PUBLIC_SUPABASE_URL!,\n  process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!\n)\n\n\u002F\u002F Typed insert\nconst { data: org, error } = await supabase\n  .from('organizations')\n  .insert({ name: 'Acme Corp', slug: 'acme', plan: 'pro' })\n  .select()\n  .single()\n\n\u002F\u002F Typed select with foreign key join\nconst { data: tasks } = await supabase\n  .from('tasks')\n  .select('*, project:project_id(name, organization_id)')\n  .eq('status', 'todo')\n  .order('due_date', { ascending: true })\n\n\u002F\u002F Nested join across multiple tables\nconst { data: orgWithProjects } = await supabase\n  .from('organizations')\n  .select(`\n    id, name, slug,\n    projects:projects(\n      id, name, status,\n      tasks:tasks(id, title, status, assigned_to)\n    )\n  `)\n  .eq('slug', 'acme')\n  .single()\n```\n\nVerify RLS is working:\n\n```typescript\n\u002F\u002F This should return only rows the authenticated user can see\nconst { data, error } = await supabase.from('organizations').select('*')\n\nif (error) {\n  console.error('RLS check failed:', error.message)\n}\nconsole.log(`User can see ${data?.length ?? 0} organizations`)\n```\n\n## Output\n\n- SQL migration file under `supabase\u002Fmigrations\u002F` with all tables, constraints, and indexes\n- RLS policies matching the access control rules from requirements\n- Helper functions (`is_org_member`, `is_org_admin`) for reusable authorization checks\n- `moddatetime` triggers for automatic `updated_at` management\n- Generated TypeScript types at `types\u002Fsupabase.ts` for type-safe client queries\n- Partial indexes on frequently filtered columns (status, due_date)\n\n## Error Handling\n\n| Error | Cause | Solution |\n|-------|-------|----------|\n| `42P07: relation already exists` | Table name collision in migration | Use `create table if not exists` or rename the table |\n| `23503: foreign key violation` | Insert references a nonexistent parent row | Insert parent rows first, or check the UUID |\n| `42501: insufficient privilege` | RLS helper function permissions | Add `security definer` to the function definition |\n| `42883: function uuid_generate_v4() does not exist` | Extension not enabled | Add `create extension if not exists \"uuid-ossp\"` |\n| `supabase db push` succeeds but tables missing | Migration was already recorded | Check `supabase_migrations.schema_migrations` and repair |\n| `PGRST204: column not found` | TypeScript types out of sync | Re-run `npx supabase gen types typescript --local > types\u002Fsupabase.ts` |\n| `new row violates row-level security` | RLS policy blocks the operation | Verify `auth.uid()` matches expected value; check policy `using` clause |\n| `moddatetime` trigger fails | Extension not enabled | Add `create extension if not exists \"moddatetime\"` at top of migration |\n\n## Examples\n\n**E-commerce schema** (different domain, same pattern):\n\n```sql\ncreate table public.products (\n  id uuid default uuid_generate_v4() primary key,\n  store_id uuid references public.stores(id) on delete cascade not null,\n  name text not null,\n  price integer not null check (price >= 0),  -- cents\n  currency text default 'usd',\n  inventory integer default 0 check (inventory >= 0),\n  metadata jsonb default '{}'::jsonb,\n  is_active boolean default true,\n  created_at timestamptz default now() not null,\n  updated_at timestamptz default now() not null\n);\n\nalter table public.products enable row level security;\n\ncreate policy \"Anyone reads active products\"\n  on public.products for select\n  using (is_active = true);\n\ncreate policy \"Store owners manage products\"\n  on public.products for all\n  using (\n    exists (\n      select 1 from public.stores s\n      where s.id = store_id and s.owner_id = auth.uid()\n    )\n  );\n\ncreate trigger handle_updated_at before update on public.products\n  for each row execute procedure moddatetime(updated_at);\n```\n\n**Querying the e-commerce schema from the client:**\n\n```typescript\n\u002F\u002F Products with store info\nconst { data: products } = await supabase\n  .from('products')\n  .select('*, store:store_id(name, slug)')\n  .eq('is_active', true)\n  .gte('inventory', 1)\n  .order('price', { ascending: true })\n  .limit(20)\n```\n\n## Resources\n\n- [Row Level Security Guide](https:\u002F\u002Fsupabase.com\u002Fdocs\u002Fguides\u002Fdatabase\u002Fpostgres\u002Frow-level-security)\n- [Database Migrations](https:\u002F\u002Fsupabase.com\u002Fdocs\u002Fguides\u002Fdeployment\u002Fdatabase-migrations)\n- [Supabase CLI Reference](https:\u002F\u002Fsupabase.com\u002Fdocs\u002Freference\u002Fcli)\n- [JavaScript Client — Select](https:\u002F\u002Fsupabase.com\u002Fdocs\u002Freference\u002Fjavascript\u002Fselect)\n- [TypeScript Support](https:\u002F\u002Fsupabase.com\u002Fdocs\u002Fguides\u002Fapi\u002Frest\u002Fgenerating-types)\n- [PostgreSQL Data Types](https:\u002F\u002Fwww.postgresql.org\u002Fdocs\u002Fcurrent\u002Fdatatype.html)\n\n## Next Steps\n\nFor auth integration, file storage, and realtime subscriptions on top of this schema, proceed to `supabase-auth-storage-realtime-core`.\n",{"name":5,"tags":24,"author":32,"license":15,"version":33,"description":34,"allowed-tools":35,"compatible-with":36},[25,26,27,28,29,30,31],"saas","supabase","database","migration","schema-design","postgres","rls","Jeremy Longshore \u003Cjeremy@intentsolutions.io>","1.0.0","Design Supabase Postgres schema from business requirements with migrations, RLS, and types.\nUse when translating specifications into database tables, creating migration files,\nadding Row Level Security policies, or generating TypeScript types from schema.\nTrigger with phrases like \"supabase schema\", \"design database supabase\",\n\"schema from requirements\", \"supabase migration\", \"supabase tables from spec\".\n","Read, Write, Edit, Bash(supabase:*), Bash(npx:*), Grep","claude-code, codex, openclaw","main","99825ad3f3bcc6597ddcc7294a14e6e922f2b67b","skills\u002Fsaas-packs--supabase-pack--supabase-schema-from-requirements",0,"https:\u002F\u002Fgithub.com\u002Fjukeyman\u002Fjukeyman-skills","https:\u002F\u002Fgithub.com\u002Fjukeyman","https:\u002F\u002FRJBUSINESSSOLUTIONS.ORG","Credit and Finance Expert | Developer\r\n\r\nI'm Rick Jefferson, a seasoned credit and finance expert with over a decade of experience in financial literacy,","2026-07-13 07:03:29",{"source":8,"skillName":5,"commands":47,"prompt":57,"zipAvailable":58},[48,51,54],{"tool":49,"command":50},"npx","npx skills add jukeyman\u002Fjukeyman-skills --skill supabase-schema-from-requirements",{"tool":52,"command":53},"bunx","bunx skills add jukeyman\u002Fjukeyman-skills --skill supabase-schema-from-requirements",{"tool":55,"command":56},"pnpm","pnpm dlx skills add jukeyman\u002Fjukeyman-skills --skill supabase-schema-from-requirements","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fjukeyman\u002Fjukeyman-skills\u002Fblob\u002Fmain\u002Fskills\u002Fsaas-packs--supabase-pack--supabase-schema-from-requirements\u002FSKILL.md",true,[],[61,68,75,82,89,97],{"skillNo":62,"name":63,"nameZh":6,"description":64,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":65,"categories":66,"keywords":67,"publishedAt":19},"01M79ANS2SM329NEP5ZCX106RR","zustand-store-creator","Create zustand store creator operations. Auto-activating skill for Frontend Development.\nTriggers on: zustand store creator, zustand store creator\nPart of the Frontend Development skill category. Use when working with zustand store creator functionality. Trigger with phrases like \"zustand store creator\", \"zustand creator\", \"zustand\".","https:\u002F\u002Fgithub.com\u002Fjukeyman\u002Fjukeyman-skills\u002Fblob\u002Fmain\u002Fskills\u002Fzustand-store-creator\u002FSKILL.md",[],[],{"skillNo":69,"name":70,"nameZh":6,"description":71,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":72,"categories":73,"keywords":74,"publishedAt":19},"01M79AMZKP4YDEZ7EHG1Y7PP74","zero-trust-config-helper","Configure with zero trust config helper operations. Auto-activating skill for Security Advanced.\nTriggers on: zero trust config helper, zero trust config helper\nPart of the Security Advanced skill category. Use when configuring systems or services. Trigger with phrases like \"zero trust config helper\", \"zero helper\", \"zero\".","https:\u002F\u002Fgithub.com\u002Fjukeyman\u002Fjukeyman-skills\u002Fblob\u002Fmain\u002Fskills\u002Fzero-trust-config-helper\u002FSKILL.md",[],[],{"skillNo":76,"name":77,"nameZh":6,"description":78,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":79,"categories":80,"keywords":81,"publishedAt":19},"01M79AMJSBCEJQNBTYNAHYN5HM","zapier-integration-helper","Assist with zapier integration helper operations. Auto-activating skill for Business Automation.\nTriggers on: zapier integration helper, zapier integration helper\nPart of the Business Automation skill category. Use when working with APIs or building integrations. Trigger with phrases like \"zapier integration helper\", \"zapier helper\", \"zapier\".","https:\u002F\u002Fgithub.com\u002Fjukeyman\u002Fjukeyman-skills\u002Fblob\u002Fmain\u002Fskills\u002Fzapier-integration-helper\u002FSKILL.md",[],[],{"skillNo":83,"name":84,"nameZh":6,"description":85,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":86,"categories":87,"keywords":88,"publishedAt":19},"01M79AHJZGVMARS13VFQYRR1MP","yaml-config-validator","Validate yaml config validator operations. Auto-activating skill for DevOps Basics.\nTriggers on: yaml config validator, yaml config validator\nPart of the DevOps Basics skill category. Use when configuring systems or services. Trigger with phrases like \"yaml config validator\", \"yaml validator\", \"yaml\".","https:\u002F\u002Fgithub.com\u002Fjukeyman\u002Fjukeyman-skills\u002Fblob\u002Fmain\u002Fskills\u002Fyaml-config-validator\u002FSKILL.md",[],[],{"skillNo":90,"name":91,"nameZh":6,"description":92,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":93,"sourceHtmlUrl":94,"categories":95,"keywords":96,"publishedAt":19},"01M79AHGDZRN0020RDQSQDPAM8","xvary-stock-research","Thesis-driven equity analysis from public SEC EDGAR and market data; \u002Fanalyze, \u002Fscore, \u002Fcompare workflows with bundled Python tools (Claude Code, Cursor, Codex).","https:\u002F\u002Fgithub.com\u002Fjukeyman\u002Fjukeyman-skills\u002Fblob\u002Fmain\u002Fskills\u002Fxvary-stock-research\u002FLICENSE","https:\u002F\u002Fgithub.com\u002Fjukeyman\u002Fjukeyman-skills\u002Fblob\u002Fmain\u002Fskills\u002Fxvary-stock-research\u002FSKILL.md",[],[],{"skillNo":98,"name":99,"nameZh":6,"description":100,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":101,"categories":102,"keywords":103,"publishedAt":19},"01M79AHCYJ9FV9RMHQ24HDRN33","xss-vulnerability-scanner","Scan xss vulnerability scanner operations. Auto-activating skill for Security Fundamentals.\nTriggers on: xss vulnerability scanner, xss vulnerability scanner\nPart of the Security Fundamentals skill category. Use when working with xss vulnerability scanner functionality. Trigger with phrases like \"xss vulnerability scanner\", \"xss scanner\", \"xss\".","https:\u002F\u002Fgithub.com\u002Fjukeyman\u002Fjukeyman-skills\u002Fblob\u002Fmain\u002Fskills\u002Fxss-vulnerability-scanner\u002FSKILL.md",[],[]]