Schema location
prisma/schema.prisma
Applying schema changes
pnpm install --silent is required first because prisma.config.ts imports from the prisma package.
Do not add a
url property to the datasource block in schema.prisma. Database URLs are configured in prisma.config.ts.Built-in models
User (do not modify fields)
User from other models. Use externalId to map to internal user IDs.
Organization
For multi-tenant apps, use the built-in organization tables:ctx.currentOrgId for organization-scoped data:
Additional built-in models
Beyond User and Organization, the scaffolded schema includes framework-managed models for:
These models are managed by the framework and their RLS policies are configured in
scopes.json. You do not need to modify them.
Database access
Always usectx.db in procedure handlers. It injects RLS context automatically.
Indexing requirements
Prisma does not automatically create indexes on foreign key columns. Add@@index explicitly for:
Relations and data fetching
Use Prismainclude to fetch related data in a single query:
Transactions
Use Prisma transactions for operations that must succeed or fail together:Environment differences
The framework handles the difference transparently.
User identity
Never accept user identity as tRPC input — it cannot be considered authentic, and may break due to procedure-level or RLS-level scoping. Always use
ctx.userId on the backend.
