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.

Update backfill-commissions-reward.ts

Kiran K0a353ab13ca0
diff --git a/apps/web/scripts/backfill-commissions-reward.ts b/apps/web/scripts/backfill-commissions-reward.ts
index 2ca99e5ce8..a7fdf6db04 100644
--- a/apps/web/scripts/backfill-commissions-reward.ts
+++ b/apps/web/scripts/backfill-commissions-reward.ts
@@ -2,7 +2,7 @@ import { prisma } from "@dub/prisma";
import "dotenv-flow/config";
async function main() {
- const programId = "prog_";
+ const programId = "prog_CYCu7IMAapjkRpTnr8F1azjN";
const rewards = await prisma.reward.findMany({
where: {
@@ -55,6 +55,7 @@ async function main() {
in: reward.partnerIds,
},
type: reward.event,
+ rewardType: null,
},
data: {
rewardType: reward.type,
@@ -77,20 +78,41 @@ async function main() {
console.table(rewardsWithPartners);
for (const reward of rewardsWithPartners) {
- await prisma.commission.updateMany({
- where: {
- earnings: {
- gt: 0,
+ console.log(`Processing ${reward.event} reward`);
+
+ while (true) {
+ const commissions = await prisma.commission.findMany({
+ where: {
+ earnings: {
+ gt: 0,
+ },
+ programId,
+ type: reward.event,
+ rewardType: null,
},
- programId,
- type: reward.event,
- },
- data: {
- rewardType: reward.type,
- rewardAmount: reward.amount,
- rewardMaxDuration: reward.maxDuration,
- },
- });
+ take: 1,
+ });
+
+ if (commissions.length === 0) {
+ console.log("No more commissions to update");
+ break;
+ }
+
+ console.log(`Found ${commissions.length} commissions to update`);
+
+ await prisma.commission.updateMany({
+ where: {
+ id: {
+ in: commissions.map((c) => c.id),
+ },
+ },
+ data: {
+ rewardType: reward.type,
+ rewardAmount: reward.amount,
+ rewardMaxDuration: reward.maxDuration,
+ },
+ });
+ }
}
}
}