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, }, });