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 scripts

Steven Teyc575a592d3b0
diff --git a/apps/web/scripts/misc/disable-workspace-links.ts b/apps/web/scripts/misc/disable-workspace-links.ts
index 8eb87bf2d0..d9c1a5bd73 100644
--- a/apps/web/scripts/misc/disable-workspace-links.ts
+++ b/apps/web/scripts/misc/disable-workspace-links.ts
@@ -4,7 +4,7 @@ import "dotenv-flow/config";
import { linkCache } from "../../lib/api/links/cache";
import { updateConfig } from "../../lib/edge-config";
-// script to get the top google ads campaign ids in fraud events
+// script to disable all links for a workspace
async function main() {
const project = await prisma.project.findUniqueOrThrow({
where: {
diff --git a/apps/web/scripts/misc/restore-workspace-access.ts b/apps/web/scripts/misc/restore-workspace-access.ts
new file mode 100644
index 0000000000..40f6e2cc3c
--- /dev/null
+++ b/apps/web/scripts/misc/restore-workspace-access.ts
@@ -0,0 +1,73 @@
+import { prisma } from "@dub/prisma";
+import { LEGAL_USER_ID } from "@dub/utils";
+import "dotenv-flow/config";
+import { linkCache } from "../../lib/api/links/cache";
+
+// script to restore access to a workspace for a user
+async function main() {
+ const project = await prisma.project.findUniqueOrThrow({
+ where: {
+ slug: "xxx",
+ },
+ });
+
+ const user = await prisma.user.findUniqueOrThrow({
+ where: {
+ email: project.name,
+ },
+ });
+
+ const linksToRestore = await prisma.link.findMany({
+ where: {
+ projectId: project.id,
+ disabledAt: {
+ not: null,
+ },
+ },
+ });
+
+ if (linksToRestore.length > 0) {
+ const restoredLinks = await prisma.link.updateMany({
+ where: {
+ id: {
+ in: linksToRestore.map((link) => link.id),
+ },
+ },
+ data: {
+ disabledAt: null,
+ },
+ });
+
+ console.log(`Restored ${restoredLinks.count} links`);
+
+ const res = await linkCache.expireMany(linksToRestore);
+ console.log(res);
+ }
+
+ await prisma.projectUsers.update({
+ where: {
+ userId_projectId: {
+ userId: LEGAL_USER_ID,
+ projectId: project.id,
+ },
+ },
+ data: {
+ userId: user.id,
+ },
+ });
+
+ await prisma.project.update({
+ where: {
+ id: project.id,
+ },
+ data: {
+ name: project.slug,
+ },
+ });
+
+ console.log(
+ `Restored access to project ${project.slug} for user ${user.email}`,
+ );
+}
+
+main();
diff --git a/apps/web/scripts/misc/transfer-links.ts b/apps/web/scripts/misc/transfer-links.ts
new file mode 100644
index 0000000000..0ab502e950
--- /dev/null
+++ b/apps/web/scripts/misc/transfer-links.ts
@@ -0,0 +1,89 @@
+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";
+
+// script to transfer links from one workspace to another
+async function main() {
+ const oldWorkspaceId = "ws_xxx";
+ const newWorkspaceId = "ws_xxx";
+
+ const updatedDomains = await prisma.domain.updateMany({
+ where: {
+ projectId: oldWorkspaceId,
+ },
+ data: {
+ projectId: newWorkspaceId,
+ },
+ });
+
+ console.log(`Updated ${updatedDomains.count} domains`);
+
+ const updatedRegisteredDomains = await prisma.registeredDomain.updateMany({
+ where: {
+ projectId: oldWorkspaceId,
+ },
+ data: {
+ projectId: newWorkspaceId,
+ },
+ });
+ console.log(`Updated ${updatedRegisteredDomains.count} registered domains`);
+
+ const updatedTags = await prisma.tag.updateMany({
+ where: {
+ projectId: oldWorkspaceId,
+ },
+ data: {
+ projectId: newWorkspaceId,
+ },
+ });
+
+ console.log(`Updated ${updatedTags.count} tags`);
+
+ const linksToUpdate = await prisma.link.findMany({
+ where: {
+ projectId: oldWorkspaceId,
+ },
+ });
+
+ if (linksToUpdate.length > 0) {
+ const updatedLinks = await prisma.link.updateMany({
+ where: {
+ id: {
+ in: linksToUpdate.map((link) => link.id),
+ },
+ },
+ data: {
+ projectId: newWorkspaceId,
+ folderId: null,
+ disabledAt: null,
+ },
+ });
+
+ console.log(`Updated ${updatedLinks.count} links`);
+
+ const finalLinks = await prisma.link.findMany({
+ where: {
+ id: {
+ in: linksToUpdate.map((link) => link.id),
+ },
+ },
+ include: includeTags,
+ });
+
+ const redisRes = await linkCache.expireMany(finalLinks);
+
+ // set the link with the old workspace ID to be deleted in Tinybird
+ const tbRes1 = await recordLink(linksToUpdate, { deleted: true });
+
+ // set the link with the new workspace ID to be created in Tinybird
+ const tbRes2 = await recordLink(finalLinks);
+
+ console.log("redisRes", redisRes);
+ console.log("tbRes1", tbRes1);
+ console.log("tbRes2", tbRes2);
+ }
+}
+
+main();