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.

include script

Steven Tey38f960826b1b
diff --git a/apps/web/scripts/fix-broken-root-domains.ts b/apps/web/scripts/fix-broken-root-domains.ts
new file mode 100644
index 0000000000..0d1f9e71dc
--- /dev/null
+++ b/apps/web/scripts/fix-broken-root-domains.ts
@@ -0,0 +1,65 @@
+import { createLink } from "@/lib/api/links";
+import { prisma } from "@/lib/prisma";
+import { DEFAULT_LINK_PROPS } from "@dub/utils";
+import "dotenv-flow/config";
+
+async function main() {
+ const domainsWithNoLinks = await prisma.domain.findMany({
+ where: {
+ links: {
+ none: {
+ key: "_root",
+ },
+ },
+ },
+ select: {
+ slug: true,
+ _count: {
+ select: {
+ links: true,
+ },
+ },
+ createdAt: true,
+ project: {
+ select: {
+ slug: true,
+ users: {
+ select: {
+ userId: true,
+ },
+ },
+ },
+ },
+ projectId: true,
+ },
+ take: 10,
+ orderBy: {
+ createdAt: "asc",
+ },
+ });
+
+ await Promise.all(
+ domainsWithNoLinks.map(async (domain) => {
+ if (!domain.project?.users[0].userId) {
+ console.log(`No user found for domain ${domain.slug}`);
+ return;
+ }
+
+ const res = await createLink({
+ ...DEFAULT_LINK_PROPS,
+ domain: domain.slug,
+ key: "_root",
+ url: "",
+ tags: undefined,
+ createdAt: domain.createdAt,
+ projectId: domain.projectId,
+ userId: domain.project?.users[0].userId,
+ });
+ console.log({ res });
+ }),
+ );
+
+ console.table(domainsWithNoLinks);
+}
+
+main();