mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-07 04:12:04 +00:00
The breaking changes in 18 do not reach this repository: nothing preloads dotenv with -r, nothing reads a .env.vault, and both entry points in use (the default export in prisma.config.ts and the side-effect dotenv/config import in the one-shot scripts) keep their behaviour. dotenv/config stays quiet by default. What does change is the load message, which now goes to stderr. Prisma reads prisma.config.ts on every migrate deploy at container start, so both loads there pass quiet: true rather than adding two stderr lines to each boot. The image's /opt/prisma-cli install, which the config resolves dotenv from, moves to the same 18.0.6.
41 lines
1.2 KiB
TypeScript
41 lines
1.2 KiB
TypeScript
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import dotenv from "dotenv";
|
|
import { defineConfig } from "prisma/config";
|
|
|
|
dotenv.config({ path: path.join(__dirname, ".env"), quiet: true });
|
|
dotenv.config({ path: path.join(__dirname, ".env.local"), quiet: true });
|
|
|
|
const inContainer = fs.existsSync("/.dockerenv");
|
|
const defaultDatabaseUrl = inContainer
|
|
? "postgresql://healthlog:healthlog@db:5432/healthlog?schema=public"
|
|
: "postgresql://healthlog:healthlog@localhost:5432/healthlog?schema=public";
|
|
|
|
function resolveDatabaseUrl(): string {
|
|
const configured = process.env.DATABASE_URL?.trim() || defaultDatabaseUrl;
|
|
|
|
// Host-local Prisma CLI calls cannot resolve Docker-internal hostname "db".
|
|
// Keep container behavior unchanged (Coolify / Docker runtime).
|
|
if (inContainer) return configured;
|
|
|
|
try {
|
|
const parsed = new URL(configured);
|
|
if (parsed.hostname === "db") {
|
|
parsed.hostname = "localhost";
|
|
return parsed.toString();
|
|
}
|
|
return configured;
|
|
} catch {
|
|
return configured;
|
|
}
|
|
}
|
|
|
|
const databaseUrl = resolveDatabaseUrl();
|
|
|
|
export default defineConfig({
|
|
schema: path.join(__dirname, "prisma", "schema.prisma"),
|
|
datasource: {
|
|
url: databaseUrl,
|
|
},
|
|
});
|