-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprisma.config.ts
More file actions
33 lines (29 loc) · 1.5 KB
/
prisma.config.ts
File metadata and controls
33 lines (29 loc) · 1.5 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
import 'dotenv/config'
import { defineConfig } from "prisma/config";
import { fileURLToPath } from 'url';
import { dirname, resolve } from 'path';
// Get the directory of this config file (project root)
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
// Get DATABASE_URL from environment
let databaseUrl = process.env.DATABASE_URL || '';
// If DATABASE_URL contains relative SSL cert paths, convert them to absolute
if (databaseUrl && (databaseUrl.includes('sslcert=.') || databaseUrl.includes('sslrootcert=.') || databaseUrl.includes('sslkey=.'))) {
// Replace relative paths with absolute paths
databaseUrl = databaseUrl
.replace(/sslcert=\.\/([^&]+)/g, (match, path) => `sslcert=${resolve(__dirname, path)}`)
.replace(/sslcert=([^\/][^&]+)/g, (match, path) => path.startsWith('sslcert=/') ? match : `sslcert=${resolve(__dirname, path)}`)
.replace(/sslrootcert=\.\/([^&]+)/g, (match, path) => `sslrootcert=${resolve(__dirname, path)}`)
.replace(/sslrootcert=([^\/][^&]+)/g, (match, path) => path.startsWith('sslrootcert=/') ? match : `sslrootcert=${resolve(__dirname, path)}`)
.replace(/sslkey=\.\/([^&]+)/g, (match, path) => `sslkey=${resolve(__dirname, path)}`)
.replace(/sslkey=([^\/][^&]+)/g, (match, path) => path.startsWith('sslkey=/') ? match : `sslkey=${resolve(__dirname, path)}`);
}
export default defineConfig({
schema: './prisma/schema.prisma',
datasource: {
url: databaseUrl,
},
migrations: {
path: './prisma/migrations'
}
});