Create a new Supabase SQL migration. Use when modifying the database schema.
Create a new migration: $ARGUMENTS
Read the technical plan in docs/technical-plan.md for the schema design
Read existing migrations in supabase/migrations/ to understand current schema and naming patterns
Generate a timestamped migration file:
supabase/migrations/<YYYYMMDDHHMMSS>_<description>.sql
Use: !date -u +%Y%m%d%H%M%S for the timestamp prefix.
Write the migration SQL following these rules:
-- Enable RLS on all new tables
CREATE TABLE IF NOT EXISTS table_name (
id uuid DEFAULT gen_random_uuid() PRIMARY KEY,
created_at timestamptz DEFAULT now() NOT NULL,
updated_at timestamptz DEFAULT now() NOT NULL
-- columns here
);
ALTER TABLE table_name ENABLE ROW LEVEL SECURITY;
-- Always create RLS policies
CREATE POLICY "description" ON table_name
FOR SELECT USING (auth.uid() = user_id);
Verify the SQL is valid by reviewing for:
NOT NULL constraints on required fieldsPush the migration: supabase db push
id, created_at, updated_at columnsuuid for primary keys, not serial/bigserialuuid columns