Database Overview
Prisma v7 + PostgreSQL โ the data layer powering every Nebutra application.
Nebutra-Sailor uses Prisma as the ORM and PostgreSQL as the database engine โ one source, generated, deployed first. See ADR 2026-09-25 database convergence for the full decision; this page covers day-to-day use.
Architecture
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Application Code โ
โ (Next.js Server Components, API) โ
โโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโ
โ import { db } from "@nebutra/db"
โโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโ
โ Prisma Client โ
โ (type-safe query builder) โ
โโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโ
โ PostgreSQL wire protocol
โโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโ
โ PostgreSQL Database โ
โ pgvector ยท generated RLS โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโpackages/platform/db/prisma/schema.prisma is the single source: tables, and each table's
access rule as an /// @rls comment. Everything else โ generated/rls.sql, the baseline
migration โ is generated from it or re-applied to it on every deploy (pnpm db:deploy). There is
no scaffold-time database choice; create-sailor writes this schema every time.
Schema layout
There are two Postgres schemas โ see Prisma Postgres Schemas for why:
| PostgreSQL schema | Purpose |
|---|---|
public | Every application table |
better_auth | Tables Better Auth's own plugins (organization, passkey, โฆ) manage |
This is not a "one schema per product domain" split โ there is no ecommerce, recsys, or web3
schema, and no scaffold flag that would prune one.
pgvector
PostgreSQL's pgvector extension powers AI embedding search (@nebutra/search, pgvector plus
full-text search โ there is no separate search engine). Self-hosted PostgreSQL requires
CREATE EXTENSION vector; before running migrations; the postgres:15-alpine-based image
create-sailor wires up already has it.
Command reference
| Command | When to use |
|---|---|
pnpm db:deploy | The deploy command. Runs pending migrations, then platform.sql + generated/rls.sql, then verifies. Exits non-zero on drift. |
pnpm db:check | Read-only half of db:deploy โ reports drift without applying anything |
pnpm db:generate | After editing schema.prisma โ regenerates the Prisma client and generated/rls.sql |
pnpm db:migrate | Create and apply a new migration (local development) |
pnpm db:push | Push schema changes without a migration file (local prototyping only) |
pnpm db:studio | Open Prisma Studio |
pnpm db:seed | Populate the database with development seed data |
Never run pnpm db:push against a production or staging database. It applies schema changes without a migration history, which can cause irreversible data loss. Production deploys use pnpm db:deploy.
Multi-tenancy
A table's access rule is inferred from its tenantId / organizationId column (or declared
explicitly). Queries are scoped using PostgreSQL Row-Level Security (RLS) via the withRls helper
from @nebutra/tenant. See the RLS guide for details.
How is this guide?
Last updated on