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 update-links.ts

Steven Tey35de3e2fe091
diff --git a/apps/web/scripts/testimonial/update-links.ts b/apps/web/scripts/testimonial/update-links.ts
new file mode 100644
index 0000000000..27026157a5
--- /dev/null
+++ b/apps/web/scripts/testimonial/update-links.ts
@@ -0,0 +1,46 @@
+import { prisma } from "@dub/prisma";
+import "dotenv-flow/config";
+import { linkCache } from "../../lib/api/links/cache";
+import { includeTags } from "../../lib/api/links/include-tags";
+import { recordLink } from "../../lib/tinybird";
+
+// update links
+async function main() {
+ const links = await prisma.link.findMany({
+ where: {
+ domain: "aff.testimonial.to",
+ key: {
+ not: "_root",
+ },
+ },
+ include: includeTags,
+ take: 500,
+ });
+
+ const updatedLinks = await prisma.link.updateMany({
+ where: {
+ id: {
+ in: links.map((link) => link.id),
+ },
+ },
+ data: {
+ domain: "refer.testimonial.to",
+ },
+ });
+
+ console.log(updatedLinks);
+
+ const res = await Promise.all([
+ linkCache.expireMany(links),
+ recordLink(
+ links.map((link) => ({
+ ...link,
+ domain: "refer.testimonial.to",
+ })),
+ ),
+ ]);
+
+ console.log(res);
+}
+
+main();