My-Weekly-ToDo-List/src/lib/prisma.ts
mARTin 92593cf616 fix: prevent Prisma connection pool exhaustion in production
Cache PrismaClient globally in ALL environments (was only cached in dev).
Without this, production could create multiple PrismaClient instances,
each with its own connection pool, exhausting the database connections.

v1.71.2

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-24 23:17:29 +01:00

17 lines
404 B
TypeScript

import { PrismaClient } from '@prisma/client';
const globalForPrisma = global as unknown as { prisma: PrismaClient };
export const prisma =
globalForPrisma.prisma ||
new PrismaClient({
datasources: {
db: {
url: process.env.DATABASE_URL,
},
},
});
// Cache the client globally in ALL environments to prevent connection pool exhaustion
globalForPrisma.prisma = prisma;