Skip to content

Commit f2d85da

Browse files
committed
Fix
1 parent 1614246 commit f2d85da

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

apps/sim/lib/workflows/utils.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,23 @@ export async function createWorkflowRecord(params: CreateWorkflowInput) {
436436
const workflowId = crypto.randomUUID()
437437
const now = new Date()
438438

439+
const duplicateConditions = [
440+
eq(workflowTable.workspaceId, workspaceId),
441+
isNull(workflowTable.archivedAt),
442+
eq(workflowTable.name, name),
443+
...(folderId
444+
? [eq(workflowTable.folderId, folderId)]
445+
: [isNull(workflowTable.folderId)]),
446+
]
447+
const [duplicateWorkflow] = await db
448+
.select({ id: workflowTable.id })
449+
.from(workflowTable)
450+
.where(and(...duplicateConditions))
451+
.limit(1)
452+
if (duplicateWorkflow) {
453+
throw new Error(`A workflow named "${name}" already exists in this folder. Use a different name.`)
454+
}
455+
439456
const workflowParentCondition = folderId
440457
? eq(workflowTable.folderId, folderId)
441458
: isNull(workflowTable.folderId)

0 commit comments

Comments
 (0)