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.

add backfill script, remove shared dashboards in /sync

Steven Teyedbda600a375
diff --git a/apps/web/app/api/links/sync/route.ts b/apps/web/app/api/links/sync/route.ts
index 97acb1dcfd..00e970f00d 100644
--- a/apps/web/app/api/links/sync/route.ts
+++ b/apps/web/app/api/links/sync/route.ts
@@ -61,6 +61,12 @@ export const POST = withWorkspace(
publicStats: false,
},
}),
+ // remove shared dashboards
+ prisma.sharedDashboard.deleteMany({
+ where: {
+ linkId: { in: unclaimedLinks.map((link) => link!.id) },
+ },
+ }),
propagateBulkLinkChanges(
unclaimedLinks.map((link) => ({
...link!,
diff --git a/apps/web/scripts/backfill-shared-dashboards.ts b/apps/web/scripts/backfill-shared-dashboards.ts
new file mode 100644
index 0000000000..5292b5f596
--- /dev/null
+++ b/apps/web/scripts/backfill-shared-dashboards.ts
@@ -0,0 +1,49 @@
+import { createId } from "@/lib/api/utils";
+import { prisma } from "@/lib/prisma";
+import { APP_DOMAIN } from "@dub/utils";
+import "dotenv-flow/config";
+
+async function main() {
+ const links = await prisma.link.findMany({
+ where: {
+ publicStats: true,
+ sharedDashboard: null,
+ },
+ select: {
+ id: true,
+ shortLink: true,
+ clicks: true,
+ trackConversion: true,
+ projectId: true,
+ userId: true,
+ },
+ orderBy: {
+ clicks: "desc",
+ createdAt: "desc",
+ },
+ take: 50,
+ });
+
+ const results = await Promise.all(
+ links.map(async (link) => {
+ const sharedDashboard = await prisma.sharedDashboard.create({
+ data: {
+ id: createId({ prefix: "dsh_" }),
+ linkId: link.id,
+ showConversions: link.trackConversion,
+ projectId: link.projectId,
+ userId: link.userId,
+ },
+ });
+
+ return {
+ ...link,
+ sharedDashboardUrl: `${APP_DOMAIN}/share/${sharedDashboard.id}`,
+ };
+ }),
+ );
+
+ console.table(results);
+}
+
+main();