-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprisma.config.ts
More file actions
40 lines (33 loc) · 1.17 KB
/
prisma.config.ts
File metadata and controls
40 lines (33 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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") });
dotenv.config({ path: path.join(__dirname, ".env.local") });
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,
},
});