fix(db): skip DATABASE_URL check during Next.js build phase

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 <noreply@anthropic.com>
This commit is contained in:
2026-05-21 22:11:36 +02:00
parent 63c9f750df
commit b92b1c447b
+7 -2
View File
@@ -1,10 +1,15 @@
import { drizzle } from "drizzle-orm/postgres-js"; import { drizzle } from "drizzle-orm/postgres-js";
import postgres from "postgres"; 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"); 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); export const db = drizzle(client);