Database Patterns
Drizzle ORM with PostgreSQL (Neon serverless). All database code lives in server/database/.
Quick Reference
- •Schema: See schema-patterns.md for table definitions, foreign keys, enums, and JSON fields
- •Formatting: See formatting.md for Drizzle schema formatting rules
- •Relations: See relations.md for one-to-many and many-to-one patterns
- •Queries: See queries.md for select, insert, update, delete, and transactions
- •Migrations: See migrations.md for workflow and commands
Core Principles
- •Always use indexes on foreign keys
- •ULID primary keys with
ulid()helper - •Timestamps with timezone and auto-update
- •Use
dbfromevent.contextin API routes - •Validate with Valibot before DB operations
- •Guard clauses for auth checks
- •Transactions for multi-table operations