Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions lib/prisma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ const globalForPrisma = globalThis as unknown as {
prisma: PrismaClient | undefined;
};

const connectionString = process.env.DATABASE_URL;

if (!connectionString) {
throw new Error('DATABASE_URL is not set');
}

// Prisma 7 connects through a driver adapter instead of a schema-level `url`.
// PrismaPg manages its own pg connection pool from the connection string.
const adapter = new PrismaPg({ connectionString });
// PrismaPg manages its own pg connection pool. The pool connects lazily (on the
// first query), so constructing it at import time is safe even when
// DATABASE_URL is unset — e.g. during `next build`, which imports route modules
// to collect page data. A missing URL surfaces as a clear error on first query
// rather than crashing the build.
const adapter = new PrismaPg({ connectionString: process.env.DATABASE_URL });

export const prisma =
globalForPrisma.prisma ??
Expand Down