From b92b1c447b3def4cddfcb618e2b5e7ce984a3a64 Mon Sep 17 00:00:00 2001 From: Simone Cavalli Date: Thu, 21 May 2026 22:11:36 +0200 Subject: [PATCH] fix(db): skip DATABASE_URL check during Next.js build phase MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit NEXT_PHASE=phase-production-build is set by Next.js during static analysis. Route handlers are analyzed but not executed, so the DB client is never actually used — the placeholder URL never connects to anything. Co-Authored-By: Claude Sonnet 4.6 --- src/db/index.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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);