Skip to content

Scheduling infrastructure for absolutely everyone.

feat: databaseUrl customPrisma

Agusti Fernandez Pardo6e78bf15f0e8
diff --git a/lib/helpers/customPrisma.ts b/lib/helpers/customPrisma.ts
index 98d1e3b2b25..f9da8ebe1e3 100644
--- a/lib/helpers/customPrisma.ts
+++ b/lib/helpers/customPrisma.ts
@@ -3,7 +3,7 @@ import cache from "memory-cache";
import { NextMiddleware } from "next-api-middleware";
import { PRISMA_CLIENT_CACHING_TIME } from "@calcom/api/lib/constants";
-import prismaAdmin from "@calcom/console/modules/common/utils/prisma";
+// import prismaAdmin from "@calcom/console/modules/common/utils/prisma";
import { asStringOrUndefined } from "@calcom/lib/asStringOrNull";
import { prisma, customPrisma } from "@calcom/prisma";
@@ -20,26 +20,31 @@ export const customPrismaClient: NextMiddleware = async (req, res, next) => {
const id = asStringOrUndefined(key);
// If we have a key, we check if it is valid.
- const deployment = await prismaAdmin.deployment.findUnique({
- where: { key },
- });
- if (!deployment) {
- res.status(400).json({ error: "Invalid custom credentials id" });
- return;
- }
- const credentials = deployment.databaseUrl;
- if (!credentials) {
+ // const deployment = await prismaAdmin.deployment.findUnique({
+ // where: { key },
+ // });
+ const databaseUrl = await fetch(`https://console.cal.com/api/deployments/database?key=${id}`)
+ .then((res) => res.json())
+ .then((res) => res.databaseUrl);
+
+ console.log(databaseUrl);
+ // if (!databaseUrl) {
+ // res.status(400).json({ error: "Invalid custom credentials id" });
+ // return;
+ // }
+ // const credentials = deployment.databaseUrl;
+ if (!databaseUrl) {
res.status(400).json({ error: "no databaseUrl set up at your instance yet" });
return;
}
- const hashedUrl = await hash(credentials, 12);
+ const hashedUrl = await hash(databaseUrl, 12);
const cachedPrisma = cache.get(hashedUrl);
if (!cachedPrisma) {
cache.put(
hashedUrl,
- customPrisma({ datasources: { db: { url: credentials } } }),
+ customPrisma({ datasources: { db: { url: databaseUrl } } }),
PRISMA_CLIENT_CACHING_TIME // Cache the prisma client for 24 hours
);
}
diff --git a/next.config.js b/next.config.js
index f1d3bace86e..22ff466595b 100644
--- a/next.config.js
+++ b/next.config.js
@@ -11,7 +11,6 @@ const withTM = require("next-transpile-modules")([
"@calcom/emails",
"@calcom/embed-core",
"@calcom/embed-snippet",
- "@calcom/console",
]);
module.exports = withTM({