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:
+7
-2
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user