Force initialization to be lazy, preventing docker build errors

This commit is contained in:
NeilClack
2026-02-24 10:34:44 -06:00
parent 10fd06887f
commit 9fed7acff5
+13 -2
View File
@@ -4,6 +4,10 @@ import pg from 'pg';
import { PrismaPg } from '@prisma/adapter-pg'; import { PrismaPg } from '@prisma/adapter-pg';
import { PrismaClient } from '$lib/generated/prisma/client'; import { PrismaClient } from '$lib/generated/prisma/client';
let _prisma: PrismaClient | undefined;
function getPrisma(): PrismaClient {
if (!_prisma) {
const ca_cert = process.env.DO_CA_CERTIFICATE ?? ''; const ca_cert = process.env.DO_CA_CERTIFICATE ?? '';
const pool = new pg.Pool({ const pool = new pg.Pool({
@@ -17,6 +21,13 @@ const pool = new pg.Pool({
}); });
const adapter = new PrismaPg(pool); const adapter = new PrismaPg(pool);
const prisma = new PrismaClient({ adapter }); _prisma = new PrismaClient({ adapter });
}
return _prisma;
}
export { prisma }; export const prisma = new Proxy({} as PrismaClient, {
get(_, prop) {
return (getPrisma() as Record<string | symbol, unknown>)[prop];
}
});