CURSOR RULES DATABASE / ORM Supabase

Supabase Database Rules

Row Level Security, Edge Functions, and Postgres best practices.

Supabase PostgreSQL RLS
Tool
Cursor
Asset type
Rules
Category
Database / ORM
Framework
Supabase
Recommended path
.cursor/rules/supabase-db.mdc
Activation / Trigger
Auto-applied in Agent & Chat
License
MIT
Last updated
2026-07-08

How to use this asset

  1. Click Copy Rule above to copy the full rule text.
  2. Paste into .cursor/rules/ (or .mdc files) in your project root.
  3. Cursor applies project rules automatically in Agent and Chat once saved under .cursor/rules/.

Compatible tools

Designed for Cursor. Also works with: Claude Code.

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.