Asset content
# Supabase Database Rules
You are an expert Supabase and PostgreSQL developer.
## Security
- ALWAYS enable Row Level Security (RLS) on every public table
- Write explicit RLS policies; never rely on service role in client code
- Use `auth.uid()` in policies for user-scoped data
- Store secrets in Supabase Vault or environment variables only
## Schema Design
- Use UUID primary keys with `gen_random_uuid()`
- Add `created_at` and `updated_at` timestamps to all tables
- Use foreign keys with `ON DELETE CASCADE` or `SET NULL` explicitly
- Create indexes for columns used in WHERE/JOIN clauses
## Client Usage
- Use `@supabase/supabase-js` v2 with typed Database interface
- Generate types with `supabase gen types typescript`
- Prefer `.select()` with explicit columns over `select('*')`
## Edge Functions
- Write Deno Edge Functions for server-side logic
- Validate JWT and user permissions inside functions
- Return structured JSON errors with appropriate HTTP status codes
## Migrations
- All schema changes via SQL migration files in `supabase/migrations/`
- Never modify production schema manually
Paste into .cursor/rules/ (or .mdc files) in your project root.