Skip to main content

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)

You may add relations to User from other models. Use externalId to map to internal user IDs.
To store additional user attributes, create a separate table with a relation to User (e.g., a UserProfile model) rather than modifying the User model directly.

Organization

For multi-tenant apps, use the built-in organization tables:
Filter queries by 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 use ctx.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 Prisma include 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.