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.

Create backfill-payout-quantity.ts

Kiran K4979c27eb63f
diff --git a/apps/web/scripts/backfill-payout-quantity.ts b/apps/web/scripts/backfill-payout-quantity.ts
new file mode 100644
index 0000000000..b13eb632fd
--- /dev/null
+++ b/apps/web/scripts/backfill-payout-quantity.ts
@@ -0,0 +1,29 @@
+import { prisma } from "@/lib/prisma";
+import "dotenv-flow/config";
+
+async function main() {
+ const payouts = await prisma.payout.findMany({
+ where: {
+ quantity: null,
+ type: "sales",
+ },
+ select: {
+ id: true,
+ _count: {
+ select: {
+ sales: true,
+ },
+ },
+ },
+ });
+
+ // Update the quantity for each payout
+ for (const payout of payouts) {
+ await prisma.payout.update({
+ where: { id: payout.id },
+ data: { quantity: payout._count.sales },
+ });
+ }
+}
+
+main();