Skip to content

Commit 207d6ea

Browse files
Use DATABASE_URL env in web prisma.ts
1 parent f36019b commit 207d6ea

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

packages/web/src/prisma.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,17 @@ const globalForPrisma = globalThis as unknown as { prisma: PrismaClient }
1313
// @todo: we can mark this as `__unsafePrisma` in the future once we've migrated
1414
// all of the actions & queries to use the userScopedPrismaClientExtension to avoid
1515
// accidental misuse.
16-
export const prisma = globalForPrisma.prisma || new PrismaClient()
16+
export const prisma = globalForPrisma.prisma || new PrismaClient({
17+
// @note: even though DATABASE_URL is of type string, we need to check if it's defined
18+
// because this code will be executed at build time, and env.DATABASE_URL will be undefined.
19+
...(env.DATABASE_URL ? {
20+
datasources: {
21+
db: {
22+
url: env.DATABASE_URL,
23+
},
24+
}
25+
} : {})
26+
})
1727
if (env.NODE_ENV !== "production") globalForPrisma.prisma = prisma
1828

1929
/**

0 commit comments

Comments
 (0)