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 migrate-discounts.ts

Kiran K31dbab2eaa0d
diff --git a/apps/web/scripts/migrate-discounts.ts b/apps/web/scripts/migrate-discounts.ts
new file mode 100644
index 0000000000..2ef602e7be
--- /dev/null
+++ b/apps/web/scripts/migrate-discounts.ts
@@ -0,0 +1,32 @@
+import { prisma } from "@dub/prisma";
+import "dotenv-flow/config";
+
+async function main() {
+ const discounts = await prisma.discount.findMany({
+ select: {
+ id: true,
+ duration: true,
+ interval: true,
+ },
+ });
+
+ // Move the duration + interval into maxDuration
+ for (const discount of discounts) {
+ const maxDuration = discount.duration
+ ? discount.interval === "month"
+ ? discount.duration
+ : discount.duration * 12
+ : null;
+
+ await prisma.discount.update({
+ where: {
+ id: discount.id,
+ },
+ data: {
+ maxDuration,
+ },
+ });
+ }
+}
+
+main();