diff --git a/scripts/seed-insights.ts b/scripts/seed-insights.ts index 64413c8f9e..ee3757a037 100644 --- a/scripts/seed-insights.ts +++ b/scripts/seed-insights.ts @@ -3,8 +3,8 @@ import { v4 as uuidv4 } from "uuid"; import dayjs from "@calcom/dayjs"; import { hashPassword } from "@calcom/lib/auth/hashPassword"; +import { prisma } from "@calcom/prisma"; import type { Prisma } from "@calcom/prisma/client"; -import { prisma } from "@calcom/prisma/client"; import { BookingStatus, AssignmentReasonEnum } from "@calcom/prisma/enums"; import { seedAttributes, seedRoutingFormResponses, seedRoutingForms } from "./seed-utils"; @@ -367,33 +367,27 @@ async function main() { } async function runMain() { - await prisma.$connect(); - await main(); -} - -runMain() - .then(async () => { - await prisma.$disconnect(); - }) - .catch(async (e) => { - console.error(e); - await prisma.user.deleteMany({ - where: { - email: { - in: ["insights@example", "insightsuser@example.com"], + await main() + .catch(async (e) => { + console.error(e); + await prisma.user.deleteMany({ + where: { + email: { + in: ["insights@example", "insightsuser@example.com"], + }, }, - }, - }); + }); - await prisma.team.deleteMany({ - where: { - slug: "insights", - }, - }); + await prisma.team.deleteMany({ + where: { + slug: "insights", + }, + }); - await prisma.$disconnect(); - process.exit(1); - }); + await prisma.$disconnect(); + process.exit(1); + }); +} /** * This will create many users in insights teams with bookings 1y in the past @@ -530,24 +524,34 @@ async function createPerformanceData() { } } -async function runSeed() { - await prisma.$connect(); - await createPerformanceData(); +async function runPerformanceData() { + await createPerformanceData() + .catch(async (e) => { + console.error(e); + await prisma.user.deleteMany({ + where: { + username: { + contains: "insights-user-", + }, + }, + }); + await prisma.$disconnect(); + process.exit(1); + }); } -runSeed() - .then(async () => { - await prisma.$disconnect(); - }) - .catch(async (e) => { +async function runEverything() { + await prisma.$connect(); + + await runMain(); + await runPerformanceData(); +} + +runEverything() + .catch((e) => { console.error(e); - await prisma.user.deleteMany({ - where: { - username: { - contains: "insights-user-", - }, - }, - }); - await prisma.$disconnect(); process.exit(1); + }) + .finally(async () => { + await prisma.$disconnect(); });