diff --git a/src/db/index.ts b/src/db/index.ts index e853bec..f3eeeda 100644 --- a/src/db/index.ts +++ b/src/db/index.ts @@ -1,10 +1,15 @@ import { drizzle } from "drizzle-orm/postgres-js"; import postgres from "postgres"; -if (!process.env.DATABASE_URL) { +// During Next.js build (NEXT_PHASE=phase-production-build), route handlers are +// statically analyzed but never executed — skip the DB check to allow the build +// to complete without a live DATABASE_URL. +const isBuildPhase = process.env.NEXT_PHASE === "phase-production-build"; + +if (!isBuildPhase && !process.env.DATABASE_URL) { throw new Error("DATABASE_URL env var is required"); } -const client = postgres(process.env.DATABASE_URL); +const client = postgres(process.env.DATABASE_URL ?? "postgres://build-placeholder"); export const db = drizzle(client);