Generate Supabase SQL migrations with RLS policies, then regenerate TypeScript types
You generate Supabase SQL migrations for Nessi's PostgreSQL database, including Row Level Security (RLS) policies.
Change description: {{ change }}
src/types/database.ts (auto-generated via pnpm db:types)src/libs/supabase/ (browser, server, admin)products, product_images (check src/types/database.ts for current schema)auth.uid())src/types/database.tsCreate the migration file at supabase/migrations/{timestamp}_{snake_case_description}.sql:
-- Migration: {description}
-- Created: {timestamp}
-- Create table
create table public.{table_name} (
id uuid primary key default gen_random_uuid(),
-- columns here
created_at timestamptz not null default now(),
updated_at timestamptz not null default now()
);
-- Enable RLS
alter table public.{table_name} enable row level security;
-- RLS Policies
create policy "{table_name}_select_policy"
on public.{table_name}
for select
using (true); -- or (auth.uid() = user_id) for private data
create policy "{table_name}_insert_policy"
on public.{table_name}
for insert
with check (auth.uid() = user_id);
create policy "{table_name}_update_policy"
on public.{table_name}
for update
using (auth.uid() = user_id);
create policy "{table_name}_delete_policy"
on public.{table_name}
for delete
using (auth.uid() = user_id);
-- Indexes
create index idx_{table_name}_{column} on public.{table_name}({column});
-- Updated_at trigger
create trigger set_{table_name}_updated_at
before update on public.{table_name}
for each row execute function public.handle_updated_at();
Note: The handle_updated_at() function must exist in the database. If this is the first migration using it, create it first:
-- Create updated_at trigger function (if not exists)
create or replace function public.handle_updated_at()
returns trigger as $$
begin
new.updated_at = now();
return new;
end;
$$ language plpgsql;
Display the migration and ask for confirmation before applying:
💾 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
DB Migration — {description}
File: supabase/migrations/{filename}.sql
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Changes:
+ Table: {table_name} ({column_count} columns)
+ RLS: {policy_count} policies
+ Indexes: {index_count}
Apply this migration? (y/n)
After confirmation:
supabase db pushpnpm db:typessrc/types/database.tsid uuid primary key default gen_random_uuid()created_at timestamptz not null default now()uuid typestimestamptz not timestamp (timezone-aware){table}_{operation}_policy{timestamp}_{description}.sql