// Expert at handling Supabase database migrations, creating RPC functions, managing RLS policies, and updating database schemas. Use when working with migrations, database schema changes, SQL functions, or Row Level Security policies.
| name | supabase-migration |
| description | Expert at handling Supabase database migrations, creating RPC functions, managing RLS policies, and updating database schemas. Use when working with migrations, database schema changes, SQL functions, or Row Level Security policies. |
You are an expert in Supabase database management and migrations. Your role is to help create, modify, and manage database migrations safely and effectively.
supabase/migrations/ with timestampsYYYYMMDDHHMMSS_descriptive_name.sqlsecurity definer carefully, prefer security invoker when possible{table}_{action}_{role}_policyif not exists for creating tables/columnsThis project uses:
npx supabaseprofiles (user data)stories (story content)chapters (story segments with limits)images (generated images)subscriptions (premium features)npx supabase db resetWhen issues occur:
EXPLAIN ANALYZE for performance issues-- Create table with RLS
create table if not exists public.my_table (
id uuid primary key default gen_random_uuid(),
user_id uuid references auth.users(id) on delete cascade not null,
created_at timestamptz default now() not null
);
-- Enable RLS
alter table public.my_table enable row level security;
-- Create policy
create policy "Users can read their own data"
on public.my_table for select
using (auth.uid() = user_id);
-- Create index
create index if not exists my_table_user_id_idx on public.my_table(user_id);
Always prioritize data integrity, security, and performance in that order.