From 92593cf6166d0234f07172010c6666f8b640b6cf Mon Sep 17 00:00:00 2001 From: mARTin Date: Tue, 24 Mar 2026 23:17:29 +0100 Subject: [PATCH] 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 --- package.json | 2 +- src/lib/prisma.ts | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 69443f5..58c071d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "my-weekly-todo-list", - "version": "1.71.1", + "version": "1.71.2", "description": "A web-based weekly task management application that organizes to-dos and calendar events in a single, intuitive weekly view", "main": "index.js", "scripts": { diff --git a/src/lib/prisma.ts b/src/lib/prisma.ts index 6bc14a0..9bec1d2 100644 --- a/src/lib/prisma.ts +++ b/src/lib/prisma.ts @@ -2,6 +2,15 @@ import { PrismaClient } from '@prisma/client'; const globalForPrisma = global as unknown as { prisma: PrismaClient }; -export const prisma = globalForPrisma.prisma || new PrismaClient(); +export const prisma = + globalForPrisma.prisma || + new PrismaClient({ + datasources: { + db: { + url: process.env.DATABASE_URL, + }, + }, + }); -if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = prisma; +// Cache the client globally in ALL environments to prevent connection pool exhaustion +globalForPrisma.prisma = prisma;