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 {