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

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 schemaPurpose
publicEvery application table
better_authTables 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

CommandWhen to use
pnpm db:deployThe deploy command. Runs pending migrations, then platform.sql + generated/rls.sql, then verifies. Exits non-zero on drift.
pnpm db:checkRead-only half of db:deploy โ€” reports drift without applying anything
pnpm db:generateAfter editing schema.prisma โ€” regenerates the Prisma client and generated/rls.sql
pnpm db:migrateCreate and apply a new migration (local development)
pnpm db:pushPush schema changes without a migration file (local prototyping only)
pnpm db:studioOpen Prisma Studio
pnpm db:seedPopulate 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.

Using the DB Client

How to query the database from server components and API routes

Schema & Migrations

Editing the Prisma schema and running migrations safely

Row-Level Security

How RLS enforces tenant isolation at the database level

Providers

Local Postgres and other PostgreSQL-compatible hosts.

How is this guide?

Edit on GitHub

Last updated on

On this page

Architecture
Schema layout
pgvector
Command reference
Multi-tenancy