Stratum + Prisma
Type-safe ORM with declarative schema
Prisma is the most popular TypeScript ORM, known for its type-safe client and declarative schema language. Stratum works alongside Prisma. It does not replace it. Prisma handles your application's data modeling and queries. Stratum handles tenant hierarchy, config inheritance, isolation strategy, and compliance operations on the same PostgreSQL database.
Step-by-step setup: Prisma and PostgreSQL RLS guide in the Stratum docs.
Feature comparison
CapabilityPrismaStratum
Schema managementPrisma Migrate (declarative)Stratum manages tenant tables only
RLS isolationManual: raw SQL in migrationsAutomatic policy generation per tenant
Schema-per-tenantMultiple PrismaClient instancesSingle connection, search_path switching
Tenant context in queriesManual where: { tenantId } on every queryAutomatic via RLS or search_path
Config inheritanceNot availableBuilt-in, root-to-leaf resolution
Audit loggingPrisma middleware (manual)Every mutation, actor-attributed
GDPR export/purgeBuild it yourselfBuilt-in per-tenant operations
Type safetyFull generated typesTypeScript types + Zod schemas
Getting started
prisma-with-stratum.ts
import { PrismaClient } from "@prisma/client"; import { Stratum } from "@stratum-hq/lib"; // Prisma handles your app schema const prisma = new PrismaClient(); // Stratum handles tenancy on the same database const stratum = new Stratum({ pool, autoMigrate: true }); await stratum.initialize(); // Create tenant hierarchy const org = await stratum.createTenant({ name: "Acme", slug: "acme" }); // Use Prisma for app queries, Stratum for tenant ops const users = await prisma.user.findMany({ where: { tenantId: org.id } });
Things to know
- Prisma Migrate and Stratum migrations are independent. Run both during deployment.
- When using schema-per-tenant isolation, Prisma needs a separate client per schema or use $executeRaw to SET search_path.
- Prisma's connection pool and Stratum's pool are separate. Configure both for your connection limit.
Start building with Prisma + Stratum
npm install @stratum-hq/lib pg