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 migration script

Kiran Ka9754ffe2991
diff --git a/apps/web/scripts/migrate-domains.ts b/apps/web/scripts/migrate-domains.ts
index c285603e1c..29cde0d956 100644
--- a/apps/web/scripts/migrate-domains.ts
+++ b/apps/web/scripts/migrate-domains.ts
@@ -1,4 +1,3 @@
-import { createLink } from "@/lib/api/links";
import { prisma } from "@/lib/prisma";
import "dotenv-flow/config";
@@ -21,20 +20,18 @@ async function main() {
take: 5000, // TODO: Adjust this based on the number of domains
});
- const promises = domains.map(async (domain) => {
- const user = domain?.project?.users[0];
- const workspace = domain.project!;
-
- const link = await createLink({
+ // Create links for each domain
+ const newLinks = domains.map((domain) => {
+ return {
id: domain.id,
domain: domain.slug,
key: "_root",
description: domain.description,
publicStats: domain.publicStats,
projectId: domain.projectId,
- userId: user?.id,
+ userId: domain.project?.users[0].id,
createdAt: domain.createdAt,
- ...(workspace.plan === "free"
+ ...(domain.project?.plan === "free"
? {
url: "",
expiredUrl: null,
@@ -47,23 +44,57 @@ async function main() {
rewrite: domain.type === "rewrite",
noindex: domain.noindex,
}),
- archived: false,
- proxy: false,
- trackConversion: false,
- });
+ };
+ });
- return await prisma.link.update({
- where: {
- id: link.id,
- },
- data: {
- lastClicked: domain.lastClicked,
- clicks: domain.clicks,
- },
- });
+ const result = await prisma.link.createMany({
+ data: newLinks,
+ skipDuplicates: true,
});
- const result = await Promise.allSettled(promises);
+ // const promises = domains.map(async (domain) => {
+ // const user = domain?.project?.users[0];
+ // const workspace = domain.project!;
+
+ // const link = await createLink({
+ // id: domain.id,
+ // domain: domain.slug,
+ // key: "_root",
+ // description: domain.description,
+ // publicStats: domain.publicStats,
+ // projectId: domain.projectId,
+ // userId: user?.id,
+ // createdAt: domain.createdAt,
+ // ...(workspace.plan === "free"
+ // ? {
+ // url: "",
+ // expiredUrl: null,
+ // rewrite: false,
+ // noindex: false,
+ // }
+ // : {
+ // url: domain.target || "",
+ // expiredUrl: domain.expiredUrl || null,
+ // rewrite: domain.type === "rewrite",
+ // noindex: domain.noindex,
+ // }),
+ // archived: false,
+ // proxy: false,
+ // trackConversion: false,
+ // });
+
+ // return await prisma.link.update({
+ // where: {
+ // id: link.id,
+ // },
+ // data: {
+ // lastClicked: domain.lastClicked,
+ // clicks: domain.clicks,
+ // },
+ // });
+ // });
+
+ // const result = await Promise.allSettled(promises);
console.log(result);
}