Welcome to Nebutra Sailor Docs ๐ŸŽ‰
ChangelogIntroductionLicensing
Help Center (External) โ†—

Prisma Postgres Schemas

Why the database uses two Postgres schemas, not one giant public schema

Per ADR 2026-09-25 database convergence, packages/platform/db/prisma/schema.prisma is the single source for the database: every table, and every table's access rule as an /// @rls comment. There is no scaffold-time choice about database structure โ€” create-sailor writes the same schema every time.

Two Postgres schemas, not one per domain

datasource db {
  provider   = "postgresql"
  extensions = [vector, uuid_ossp(map: "uuid-ossp")]
  schemas    = ["public", "better_auth"]
}
  • public โ€” every application table, each carrying its own @@schema("public") and an /// @rls access-rule annotation.
  • better_auth โ€” the tables Better Auth's own plugins (organization, passkey, โ€ฆ) manage. Kept separate because the device-authorization flow's own table (public.auth_device_codes) has to live in public instead, where a Kysely-based edge runtime (no Prisma) can address it by literal name โ€” see ADR 2026-09-24 ยง8.

This is not a "microservice-per-schema" pattern, and there is no stripe or ai schema to prune based on a scaffold choice โ€” the old provider-choice flags that implied one don't exist.

Row-level security is generated, not hand-written

A model's access rule is inferred automatically from a tenantId / organizationId column, or from its single tenant-scoped parent relation โ€” no annotation needed for the common case. Any other model must declare one explicitly, or prisma generate fails:

/// @rls self
model Session {
  // ... only the owning user's row is visible
  @@schema("public")
}

The full vocabulary: global | deny | off | self | via(field) | using(sql) | read(sql) write(sql).

prisma generate runs a custom generator (prisma/generators/rls.mjs) that turns every /// @rls comment into a policy in generated/rls.sql. See Row-Level Security for the full annotation vocabulary and the pnpm db:deploy flow that applies it.

Related

Database Overview

Schema, generated client, and the deploy flow.

Row-Level Security

The /// @rls annotation vocabulary and the generated policy model.

How is this guide?

Edit on GitHub

Last updated on

On this page

Two Postgres schemas, not one per domain
Row-level security is generated, not hand-written
Related