Drizzle ORM Setup

Configure Drizzle ORM with your Supabase Postgres database connection.

Prerequisites

Supabase environment variables configured

Your .env.local file should contain the Postgres connection string from Supabase.

Verify with

grep POSTGRES_URI .env.local

Expected: POSTGRES_URI=postgresql://...

Follow the Supabase Setup guide to configure your environment variables, including the POSTGRES_URI connection string.

Supabase Setup Guide

For best results, run this prompt in plan mode.

Prompt

Set up Drizzle ORM for this project with Supabase Postgres.

Requirements:
1. Install drizzle-orm and drizzle-kit as dependencies
2. Create a drizzle.config.ts file in the project root configured to:
   - Use the POSTGRES_URI environment variable for the database connection
   - Output migrations to a drizzle folder
   - Use the src/db/schema.ts file for the schema
3. Create src/db/index.ts that exports a configured drizzle client using the POSTGRES_URI
4. Create src/db/schema.ts with an empty schema file that's ready for table definitions
5. Add the following scripts to package.json:
   - "db:generate": "drizzle-kit generate"
   - "db:migrate": "drizzle-kit migrate"
   - "db:studio": "drizzle-kit studio"
6. Create CLAUDE.md in the project root if it doesn't exist, and add a "Database" section containing concise instructions:
   - Commands for generating and applying migrations (db:generate, db:migrate)
   - Always include Row Level Security (RLS) policies when creating table migrations
   - Prefer configuration via custom SQL migrations when possible (e.g., Supabase storage buckets, database functions, triggers)

Use the postgres-js driver (drizzle-orm/postgres-js with the postgres package). Make sure to handle the SSL connection properly for Supabase.