Force initialization to be lazy, preventing docker build errors
This commit is contained in:
+18
-7
@@ -4,9 +4,13 @@ import pg from 'pg';
|
||||
import { PrismaPg } from '@prisma/adapter-pg';
|
||||
import { PrismaClient } from '$lib/generated/prisma/client';
|
||||
|
||||
const ca_cert = process.env.DO_CA_CERTIFICATE ?? '';
|
||||
let _prisma: PrismaClient | undefined;
|
||||
|
||||
const pool = new pg.Pool({
|
||||
function getPrisma(): PrismaClient {
|
||||
if (!_prisma) {
|
||||
const ca_cert = process.env.DO_CA_CERTIFICATE ?? '';
|
||||
|
||||
const pool = new pg.Pool({
|
||||
connectionString: process.env.DATABASE_URL,
|
||||
ssl: ca_cert
|
||||
? {
|
||||
@@ -14,9 +18,16 @@ const pool = new pg.Pool({
|
||||
ca: fs.readFileSync(ca_cert).toString()
|
||||
}
|
||||
: undefined
|
||||
});
|
||||
|
||||
const adapter = new PrismaPg(pool);
|
||||
_prisma = new PrismaClient({ adapter });
|
||||
}
|
||||
return _prisma;
|
||||
}
|
||||
|
||||
export const prisma = new Proxy({} as PrismaClient, {
|
||||
get(_, prop) {
|
||||
return (getPrisma() as Record<string | symbol, unknown>)[prop];
|
||||
}
|
||||
});
|
||||
|
||||
const adapter = new PrismaPg(pool);
|
||||
const prisma = new PrismaClient({ adapter });
|
||||
|
||||
export { prisma };
|
||||
|
||||
Reference in New Issue
Block a user