Vercel detecteert @prisma/client en runt automatisch `prisma generate` zonder --generator filter. Daardoor probeerde de erd-generator op Vercel te draaien en faalde op libnss3.so (puppeteer/Chrome niet beschikbaar in de build container). Cascading: de Prisma-client werd niet ge-update, runtime kreeg oude enum-waarden (ACTIVE i.p.v. OPEN). ERD is dev-only documentatie en niet meer in productie nodig. Generator + dependency + npm scripts + de gegenereerde svg verwijderd. README, prisma-client pattern en architecture docs bijgewerkt. Build script blijft `prisma generate && next build` zodat de client ook bij Vercel build-cache-hits opnieuw wordt gegenereerd.
71 lines
1.7 KiB
Markdown
71 lines
1.7 KiB
Markdown
---
|
|
title: "Prisma Client singleton"
|
|
status: active
|
|
audience: [ai-agent, contributor]
|
|
language: nl
|
|
last_updated: 2026-05-03
|
|
when_to_read: "When importing or initialising the Prisma client in server code."
|
|
---
|
|
|
|
# Patroon: Prisma Client singleton
|
|
|
|
## lib/prisma.ts
|
|
|
|
PostgreSQL via `pg` + `@prisma/adapter-pg` (Neon/Vercel).
|
|
|
|
```ts
|
|
import { PrismaClient } from '@prisma/client'
|
|
import { Pool } from 'pg'
|
|
import { PrismaPg } from '@prisma/adapter-pg'
|
|
|
|
function createPrismaClient() {
|
|
const url = process.env.DATABASE_URL
|
|
if (!url) throw new Error('DATABASE_URL is not set')
|
|
|
|
const pool = new Pool({ connectionString: url })
|
|
const adapter = new PrismaPg(pool)
|
|
return new PrismaClient({
|
|
adapter,
|
|
log: process.env.NODE_ENV === 'development' ? ['error', 'warn'] : ['error'],
|
|
})
|
|
}
|
|
|
|
const globalForPrisma = globalThis as unknown as { prisma: PrismaClient | undefined }
|
|
|
|
export const prisma = globalForPrisma.prisma ?? createPrismaClient()
|
|
|
|
if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = prisma
|
|
```
|
|
|
|
## prisma.config.ts (Prisma v7 vereiste)
|
|
|
|
```ts
|
|
import 'dotenv/config'
|
|
import { defineConfig } from 'prisma/config'
|
|
|
|
export default defineConfig({
|
|
schema: 'prisma/schema.prisma',
|
|
migrations: { path: 'prisma/migrations' },
|
|
})
|
|
```
|
|
|
|
## Prisma generator
|
|
|
|
`prisma/schema.prisma` bevat één generator:
|
|
|
|
```prisma
|
|
generator client {
|
|
provider = "prisma-client-js"
|
|
}
|
|
```
|
|
|
|
`prisma generate` bouwt de Prisma Client naar `node_modules/@prisma/client`.
|
|
|
|
## Commands
|
|
|
|
| Command | Gebruik |
|
|
|---|---|
|
|
| `npx prisma db push` | Schema synchroniseren naar de database |
|
|
| `npx prisma db seed` | Seeddata laden |
|
|
| `npx prisma generate` | Prisma Client genereren (lokaal of CI) |
|
|
| `npx prisma migrate deploy` | Pending migrations toepassen op de database |
|