The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Backfill comments into partner link details rows that have none
Rafie63929190dd4
diff --git a/apps/web/scripts/migrations/backfill-partner-link-comments.ts b/apps/web/scripts/migrations/backfill-partner-link-comments.tsindex 005525baf1..3a74464009 100644--- a/apps/web/scripts/migrations/backfill-partner-link-comments.ts+++ b/apps/web/scripts/migrations/backfill-partner-link-comments.ts@@ -12,7 +12,11 @@ async function main() {programId: { not: null },partnerId: { not: null },comments: { not: null },- partnerLinkDetails: null,+ // a partner who edited the link before this ran already has a row without comments+ OR: [+ { partnerLinkDetails: null },+ { partnerLinkDetails: { comments: null } },+ ],NOT: {comments: "",},@@ -20,6 +24,11 @@ async function main() {select: {id: true,comments: true,+ partnerLinkDetails: {+ select: {+ id: true,+ },+ },},take: BATCH_SIZE,orderBy: {@@ -31,13 +40,29 @@ async function main() {break;}+ const linksWithoutDetails = links.filter(+ ({ partnerLinkDetails }) => !partnerLinkDetails,+ );+ const linksWithDetails = links.filter(+ ({ partnerLinkDetails }) => partnerLinkDetails,+ );+await prisma.partnerLinkDetails.createMany({- data: links.map(({ id, comments }) => ({+ data: linksWithoutDetails.map(({ id, comments }) => ({linkId: id,comments,})),});+ await prisma.$transaction(+ linksWithDetails.map(({ id, comments }) =>+ prisma.partnerLinkDetails.update({+ where: { linkId: id },+ data: { comments },+ }),+ ),+ );+totalProcessed += links.length;console.log(