diff --git a/lib/prisma.ts b/lib/prisma.ts index 7305975..ee79e31 100644 --- a/lib/prisma.ts +++ b/lib/prisma.ts @@ -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 ??