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.

use raw sql to delete partners during tapfiliate and tolt import cleanup

Pedro Ladeira1a827f987a76
diff --git a/apps/web/lib/tapfiliate/cleanup-partners.ts b/apps/web/lib/tapfiliate/cleanup-partners.ts
index 67a2e332e4..c8ae2081a3 100644
--- a/apps/web/lib/tapfiliate/cleanup-partners.ts
+++ b/apps/web/lib/tapfiliate/cleanup-partners.ts
@@ -1,4 +1,5 @@
import { bulkDeleteLinks } from "@/lib/api/links/bulk-delete-links";
+import { conn } from "@/lib/planetscale";
import { prisma } from "@/lib/prisma";
import { sendEmail } from "@dub/email";
import ProgramImported from "@dub/email/templates/program-imported";
@@ -108,13 +109,20 @@ export async function cleanupPartners(payload: TapfiliateImportPayload) {
});
if (partnersWithoutUserAccount.length > 0) {
- await prisma.partner.deleteMany({
- where: {
- id: {
- in: partnersWithoutUserAccount.map(({ id }) => id),
- },
- },
- });
+ const partnerIdsToDelete = partnersWithoutUserAccount.map(
+ ({ id }) => id,
+ );
+
+ // using conn.execute here since Prisma throws on partner.deleteMany()
+ await conn.execute(
+ `DELETE FROM Partner WHERE id IN (${partnerIdsToDelete.map(() => "?").join(",")})`,
+ partnerIdsToDelete,
+ );
+
+ console.log(
+ "Removed the following partners",
+ partnersWithoutUserAccount,
+ );
}
}
}
diff --git a/apps/web/lib/tolt/cleanup-partners.ts b/apps/web/lib/tolt/cleanup-partners.ts
index fa771fe62e..cc840ec538 100644
--- a/apps/web/lib/tolt/cleanup-partners.ts
+++ b/apps/web/lib/tolt/cleanup-partners.ts
@@ -1,4 +1,5 @@
import { bulkDeleteLinks } from "@/lib/api/links/bulk-delete-links";
+import { conn } from "@/lib/planetscale";
import { prisma } from "@/lib/prisma";
import { toltImporter } from "./importer";
@@ -84,38 +85,38 @@ export async function cleanupPartners({ programId }: { programId: string }) {
);
if (removablePartnerIds.length > 0) {
- await prisma.$transaction(async (tx) => {
- // Find partners that have no user account
- const partnersWithoutUserAccount = await tx.partner.findMany({
- where: {
- id: {
- in: removablePartnerIds,
- },
- users: {
- none: {},
- },
+ // Find partners that have no user account
+ const partnersWithoutUserAccount = await prisma.partner.findMany({
+ where: {
+ id: {
+ in: removablePartnerIds,
},
- select: {
- id: true,
- email: true,
+ users: {
+ none: {},
},
- });
-
- if (partnersWithoutUserAccount.length > 0) {
- await tx.partner.deleteMany({
- where: {
- id: {
- in: partnersWithoutUserAccount.map(({ id }) => id),
- },
- },
- });
-
- console.log(
- "Removed the following partners",
- partnersWithoutUserAccount,
- );
- }
+ },
+ select: {
+ id: true,
+ email: true,
+ },
});
+
+ if (partnersWithoutUserAccount.length > 0) {
+ const partnerIdsToDelete = partnersWithoutUserAccount.map(
+ ({ id }) => id,
+ );
+
+ // using conn.execute here since Prisma throws on partner.deleteMany()
+ await conn.execute(
+ `DELETE FROM Partner WHERE id IN (${partnerIdsToDelete.map(() => "?").join(",")})`,
+ partnerIdsToDelete,
+ );
+
+ console.log(
+ "Removed the following partners",
+ partnersWithoutUserAccount,
+ );
+ }
}
}