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 staging workspace verify script and document backfill filters

Kiran Ka4e6ba42c894
diff --git a/apps/web/scripts/migrations/backfill-staging-workspaces.ts b/apps/web/scripts/migrations/backfill-staging-workspaces.ts
index 82c546f854..3f668fccb7 100644
--- a/apps/web/scripts/migrations/backfill-staging-workspaces.ts
+++ b/apps/web/scripts/migrations/backfill-staging-workspaces.ts
@@ -5,16 +5,16 @@ import "dotenv-flow/config";
const BATCH_SIZE = 10;
+// Queue a staging workspace for each production workspace that is eligible but
+// does not have one yet. Eligible workspaces have a default program, a plan
+// above free/pro, and a slug that does not already end in "-staging".
+// Each job creates the staging workspace and its staging program.
async function main() {
let totalProcessed = 0;
let totalPublished = 0;
let totalFailed = 0;
let cursor: string | undefined;
- // TODO:
- // We should skip workspaces where the staging workspace was created manually.
- // SELECT * FROM Project where plan not in ("free", "pro") and slug LIKE '%-staging';
-
while (true) {
const workspaces = await prisma.project.findMany({
where: {
@@ -26,6 +26,7 @@ async function main() {
plan: {
notIn: ["free", "pro"],
},
+ // Skip workspaces where the staging workspace was created manually.
slug: {
not: {
endsWith: "-staging",
diff --git a/apps/web/scripts/migrations/verify-staging-workspaces.ts b/apps/web/scripts/migrations/verify-staging-workspaces.ts
new file mode 100644
index 0000000000..5410797040
--- /dev/null
+++ b/apps/web/scripts/migrations/verify-staging-workspaces.ts
@@ -0,0 +1,82 @@
+import { prisma } from "@/lib/prisma";
+import { WorkspaceEnvironment } from "@prisma/client";
+import "dotenv-flow/config";
+
+// Verify eligible production workspaces that are missing a staging workspace or a staging program.
+async function main() {
+ const workspaces = await prisma.project.findMany({
+ where: {
+ environment: WorkspaceEnvironment.production,
+ defaultProgramId: {
+ not: null,
+ },
+ plan: {
+ notIn: ["free", "pro"],
+ },
+ slug: {
+ not: {
+ endsWith: "-staging",
+ },
+ },
+ },
+ select: {
+ id: true,
+ slug: true,
+ stagingWorkspaceId: true,
+ },
+ orderBy: {
+ id: "asc",
+ },
+ });
+
+ const missingStagingWorkspace = workspaces
+ .filter((workspace) => !workspace.stagingWorkspaceId)
+ .map(({ id, slug }) => ({ id, slug }));
+
+ const stagingWorkspacesWithoutProgram = await prisma.project.findMany({
+ where: {
+ id: {
+ in: workspaces.flatMap((workspace) =>
+ workspace.stagingWorkspaceId ? [workspace.stagingWorkspaceId] : [],
+ ),
+ },
+ defaultProgramId: null,
+ },
+ select: {
+ id: true,
+ },
+ });
+
+ const stagingIdsWithoutProgram = new Set(
+ stagingWorkspacesWithoutProgram.map((workspace) => workspace.id),
+ );
+
+ const missingStagingProgram = workspaces
+ .filter(
+ (workspace) =>
+ workspace.stagingWorkspaceId &&
+ stagingIdsWithoutProgram.has(workspace.stagingWorkspaceId),
+ )
+ .map(({ id, slug }) => ({ id, slug }));
+
+ console.log(
+ `${missingStagingWorkspace.length} workspaces are missing a staging workspace.`,
+ );
+
+ console.table(missingStagingWorkspace);
+
+ console.log(
+ `${missingStagingProgram.length} workspaces are missing a staging program.`,
+ );
+
+ console.table(missingStagingProgram);
+}
+
+main()
+ .catch((error) => {
+ console.error(error);
+ process.exitCode = 1;
+ })
+ .finally(async () => {
+ await prisma.$disconnect();
+ });