refactor: enhance user tables and machine ticket views
This commit is contained in:
parent
bd2f22d046
commit
28796bf105
7 changed files with 416 additions and 201 deletions
|
|
@ -1,3 +1,5 @@
|
|||
import path from "node:path"
|
||||
|
||||
import { PrismaClient } from "@prisma/client"
|
||||
|
||||
declare global {
|
||||
|
|
@ -5,14 +7,32 @@ declare global {
|
|||
}
|
||||
|
||||
// Resolve a robust DATABASE_URL for all runtimes (prod/dev)
|
||||
function resolveFileUrl(url: string) {
|
||||
if (!url.startsWith("file:")) {
|
||||
return url
|
||||
}
|
||||
|
||||
const filePath = url.slice("file:".length)
|
||||
if (filePath.startsWith("./") || filePath.startsWith("../")) {
|
||||
const schemaDir = path.resolve(process.cwd(), "prisma")
|
||||
const absolutePath = path.resolve(schemaDir, filePath)
|
||||
return `file:${absolutePath}`
|
||||
}
|
||||
if (!filePath.startsWith("/")) {
|
||||
const absolutePath = path.resolve(process.cwd(), filePath)
|
||||
return `file:${absolutePath}`
|
||||
}
|
||||
return url
|
||||
}
|
||||
|
||||
const resolvedDatabaseUrl = (() => {
|
||||
const envUrl = process.env.DATABASE_URL?.trim()
|
||||
if (envUrl && envUrl.length > 0) return envUrl
|
||||
if (envUrl && envUrl.length > 0) return resolveFileUrl(envUrl)
|
||||
// Fallbacks by environment to ensure correctness in containers
|
||||
if (process.env.NODE_ENV === "production") {
|
||||
return "file:/app/data/db.sqlite"
|
||||
}
|
||||
return "file:./prisma/db.sqlite"
|
||||
return resolveFileUrl("file:./prisma/db.sqlite")
|
||||
})()
|
||||
|
||||
export const prisma =
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue