Supabase Migration
Create a new Supabase SQL migration and update TypeScript types.
Steps
- •Read the current schema:
supabase/migrations/(latest migration file) - •Read existing types:
src/types/database.ts - •Create a new timestamped migration file:
supabase/migrations/<timestamp>_<description>.sql - •Update
src/types/database.tswith new/modified interfaces - •If new table — create data access functions or update existing ones
Conventions
- •Migration naming:
YYYYMMDDHHMMSS_description.sql(e.g.,20260207120000_add_orders_table.sql) - •RLS policies: always add Row Level Security policies for new tables
- •Timestamps: include
created_atandupdated_atwith defaults - •Soft delete: use
is_activeboolean ordeleted_attimestamp where appropriate - •Foreign keys: use
ON DELETE CASCADEorON DELETE SET NULLexplicitly - •Indexes: add indexes for frequently queried columns
- •Enums: prefer text check constraints over Postgres enums for flexibility
Type conventions in src/types/database.ts
typescript
export interface Order {
id: string
order_number: string
status: 'draft' | 'pending' | 'confirmed' | 'processing' | 'shipped' | 'delivered' | 'cancelled'
total_amount: number | null
client_id: string
created_at: string
updated_at: string
}
Reference files
- •Initial schema:
supabase/migrations/20260131000001_initial_schema.sql - •Existing types:
src/types/database.ts - •Seed data:
supabase/seed.sql - •Supabase config:
supabase/config.toml
$ARGUMENTS