Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Add script to copy program lead forms to their groups

Rafi34a4e5ef6f92
diff --git a/apps/web/scripts/migrations/backfill-group-referral-form-data.ts b/apps/web/scripts/migrations/backfill-group-referral-form-data.ts
new file mode 100644
index 0000000000..b0248c51b9
--- /dev/null
+++ b/apps/web/scripts/migrations/backfill-group-referral-form-data.ts
@@ -0,0 +1,49 @@
+import "dotenv-flow/config";
+
+import { prisma } from "@/lib/prisma";
+import { submittedLeadFormSchema } from "@/lib/zod/schemas/submitted-lead-form";
+import { Prisma } from "@prisma/client";
+
+// Copy each program's submitted lead form to all of its groups and turn the form on for them
+async function main() {
+ const programs = await prisma.program.findMany({
+ where: {
+ referralFormData: {
+ not: Prisma.AnyNull,
+ },
+ },
+ select: {
+ id: true,
+ name: true,
+ referralFormData: true,
+ },
+ });
+
+ console.log(`Found ${programs.length} programs with a submitted lead form`);
+
+ for (const program of programs) {
+ const parsed = submittedLeadFormSchema.safeParse(program.referralFormData);
+
+ if (!parsed.success) {
+ console.error(
+ `Skipping ${program.name} (${program.id}): invalid form data`,
+ parsed.error.issues,
+ );
+ continue;
+ }
+
+ const { count } = await prisma.partnerGroup.updateMany({
+ where: {
+ programId: program.id,
+ },
+ data: {
+ referralFormData: parsed.data,
+ submittedLeadsEnabledAt: new Date(),
+ },
+ });
+
+ console.log(`Updated ${count} groups for ${program.name} (${program.id})`);
+ }
+}
+
+main();