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-initiated-at.ts

Steven Tey5531b5a30734
diff --git a/apps/web/scripts/migrations/backfill-payout-initiated-at.ts b/apps/web/scripts/migrations/backfill-payout-initiated-at.ts
new file mode 100644
index 0000000000..671382ae41
--- /dev/null
+++ b/apps/web/scripts/migrations/backfill-payout-initiated-at.ts
@@ -0,0 +1,30 @@
+import { prisma } from "@dub/prisma";
+import "dotenv-flow/config";
+
+async function main() {
+ const invoices = await prisma.invoice.findMany({
+ where: {
+ type: "partnerPayout",
+ payouts: {
+ some: {
+ initiatedAt: null,
+ },
+ },
+ },
+ take: 10,
+ });
+
+ for (const invoice of invoices) {
+ const res = await prisma.payout.updateMany({
+ where: {
+ invoiceId: invoice.id,
+ },
+ data: {
+ initiatedAt: invoice.createdAt,
+ },
+ });
+ console.log(`Updated ${res.count} payouts for invoice ${invoice.id}`);
+ }
+}
+
+main();