Skip to content

Commit fcd9480

Browse files
fix: update seed-insights.ts Prisma connection handling for v6.16 (calcom#24660)
* fix: update seed-insights.ts to use correct Prisma import and connection handling - Change prisma import from named export to default export to match Prisma v6.16 changes - Update promise chain from .then().catch() to .catch().finally() for proper connection cleanup - Comment out duplicate runSeed() call that was causing the script to execute twice - Fixes TypeError: Cannot read properties of undefined (reading '$connect') Co-Authored-By: eunjae@cal.com <hey@eunjae.dev> * fix implementation --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
1 parent 09ddbe8 commit fcd9480

1 file changed

Lines changed: 43 additions & 39 deletions

File tree

scripts/seed-insights.ts

Lines changed: 43 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { v4 as uuidv4 } from "uuid";
33

44
import dayjs from "@calcom/dayjs";
55
import { hashPassword } from "@calcom/lib/auth/hashPassword";
6+
import { prisma } from "@calcom/prisma";
67
import type { Prisma } from "@calcom/prisma/client";
7-
import { prisma } from "@calcom/prisma/client";
88
import { BookingStatus, AssignmentReasonEnum } from "@calcom/prisma/enums";
99

1010
import { seedAttributes, seedRoutingFormResponses, seedRoutingForms } from "./seed-utils";
@@ -367,33 +367,27 @@ async function main() {
367367
}
368368

369369
async function runMain() {
370-
await prisma.$connect();
371-
await main();
372-
}
370+
await main()
371+
.catch(async (e) => {
372+
console.error(e);
373+
await prisma.user.deleteMany({
374+
where: {
375+
email: {
376+
in: ["insights@example", "insightsuser@example.com"],
377+
},
378+
},
379+
});
373380

374-
runMain()
375-
.then(async () => {
376-
await prisma.$disconnect();
377-
})
378-
.catch(async (e) => {
379-
console.error(e);
380-
await prisma.user.deleteMany({
381-
where: {
382-
email: {
383-
in: ["insights@example", "insightsuser@example.com"],
381+
await prisma.team.deleteMany({
382+
where: {
383+
slug: "insights",
384384
},
385-
},
386-
});
385+
});
387386

388-
await prisma.team.deleteMany({
389-
where: {
390-
slug: "insights",
391-
},
387+
await prisma.$disconnect();
388+
process.exit(1);
392389
});
393-
394-
await prisma.$disconnect();
395-
process.exit(1);
396-
});
390+
}
397391

398392
/**
399393
* This will create many users in insights teams with bookings 1y in the past
@@ -530,24 +524,34 @@ async function createPerformanceData() {
530524
}
531525
}
532526

533-
async function runSeed() {
527+
async function runPerformanceData() {
528+
await createPerformanceData()
529+
.catch(async (e) => {
530+
console.error(e);
531+
await prisma.user.deleteMany({
532+
where: {
533+
username: {
534+
contains: "insights-user-",
535+
},
536+
},
537+
});
538+
await prisma.$disconnect();
539+
process.exit(1);
540+
});
541+
}
542+
543+
async function runEverything() {
534544
await prisma.$connect();
535-
await createPerformanceData();
545+
546+
await runMain();
547+
await runPerformanceData();
536548
}
537549

538-
runSeed()
539-
.then(async () => {
540-
await prisma.$disconnect();
541-
})
542-
.catch(async (e) => {
550+
runEverything()
551+
.catch((e) => {
543552
console.error(e);
544-
await prisma.user.deleteMany({
545-
where: {
546-
username: {
547-
contains: "insights-user-",
548-
},
549-
},
550-
});
551-
await prisma.$disconnect();
552553
process.exit(1);
554+
})
555+
.finally(async () => {
556+
await prisma.$disconnect();
553557
});

0 commit comments

Comments
 (0)