From 59307e22bd7da333b68da3e08d8984513ef8f23f Mon Sep 17 00:00:00 2001 From: Siddharth Ganesan <33737564+Sg312@users.noreply.github.com> Date: Sun, 22 Mar 2026 02:28:42 -0700 Subject: [PATCH] fix(mothership): workflow name constraints (#3710) * Fix * Fix lint --- apps/sim/lib/workflows/utils.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/apps/sim/lib/workflows/utils.ts b/apps/sim/lib/workflows/utils.ts index d5c50b47ee..0fe3409409 100644 --- a/apps/sim/lib/workflows/utils.ts +++ b/apps/sim/lib/workflows/utils.ts @@ -436,6 +436,23 @@ export async function createWorkflowRecord(params: CreateWorkflowInput) { const workflowId = crypto.randomUUID() const now = new Date() + const duplicateConditions = [ + eq(workflowTable.workspaceId, workspaceId), + isNull(workflowTable.archivedAt), + eq(workflowTable.name, name), + ...(folderId ? [eq(workflowTable.folderId, folderId)] : [isNull(workflowTable.folderId)]), + ] + const [duplicateWorkflow] = await db + .select({ id: workflowTable.id }) + .from(workflowTable) + .where(and(...duplicateConditions)) + .limit(1) + if (duplicateWorkflow) { + throw new Error( + `A workflow named "${name}" already exists in this folder. Use a different name.` + ) + } + const workflowParentCondition = folderId ? eq(workflowTable.folderId, folderId) : isNull(workflowTable.folderId)