import { defineConfig, env } from "prisma/config";

// Prisma's CLI only auto-loads `.env` by default. This project follows
// Next.js's convention of keeping real values in `.env.local` (see
// CLAUDE.md), but not every environment this runs in necessarily follows
// that same convention (e.g. deploy tooling that only sets up a plain
// `.env`) — try both, in the same precedence Next.js itself uses.
// loadEnvFile() never overrides a variable that's already set, so trying
// `.env.local` first means it wins if both happen to define DATABASE_URL.
for (const file of [".env.local", ".env"]) {
  try {
    process.loadEnvFile(file);
  } catch {
    // File doesn't exist here — try the next one, or fall back to whatever
    // DATABASE_URL is already set in the environment.
  }
}

export default defineConfig({
  datasource: {
    url: env("DATABASE_URL"),
  },
});
