From 091c2dc0e4e4a81091c078d5944f2fbe5749dbbf Mon Sep 17 00:00:00 2001 From: neodk2004 Date: Sat, 6 Jun 2026 09:29:39 +0200 Subject: [PATCH] =?UTF-8?q?fix(01-01):=20load=20.env=20manually=20in=20pri?= =?UTF-8?q?sma.config.ts=20=E2=80=94=20Prisma=207=20env()=20unreliable=20o?= =?UTF-8?q?n=20Windows?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- prisma.config.ts | 26 ++++++++++++++++++++++++++ prisma/schema.prisma | 4 +--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/prisma.config.ts b/prisma.config.ts index a5c164e..66f433e 100644 --- a/prisma.config.ts +++ b/prisma.config.ts @@ -1,5 +1,31 @@ import { defineConfig } from "prisma/config"; +import { readFileSync, existsSync } from "fs"; +import { resolve } from "path"; + +// Prisma 7's env() helper doesn't reliably load .env on all platforms. +// Load it manually so DATABASE_URL is available when this config is evaluated. +function loadEnvFile(filename: string) { + const envPath = resolve(process.cwd(), filename); + if (!existsSync(envPath)) return; + const lines = readFileSync(envPath, "utf-8").split(/\r?\n/); + for (const line of lines) { + const match = line.match(/^([^#\s][^=]*)=(.*)$/); + if (!match) continue; + const key = match[1].trim(); + const value = match[2].trim().replace(/^["']|["']$/g, ""); + if (!(key in process.env)) process.env[key] = value; + } +} + +loadEnvFile(".env"); +loadEnvFile(".env.local"); // Next.js convention — takes priority + +const databaseUrl = process.env.DATABASE_URL; +if (!databaseUrl) throw new Error("DATABASE_URL is not set in .env or .env.local"); export default defineConfig({ schema: "prisma/schema.prisma", + datasource: { + url: databaseUrl, + }, }); diff --git a/prisma/schema.prisma b/prisma/schema.prisma index ac3cceb..f9238a9 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -3,9 +3,7 @@ generator client { } datasource db { - provider = "postgresql" - url = env("DATABASE_URL") - directUrl = env("DIRECT_URL") + provider = "postgresql" } model Owner {