Skip to content

Commit 2949b3a

Browse files
committed
chore(folders): drop the dead workflow-folder write helpers
createFolderRecord, updateFolderRecord and deleteFolderRecord in lib/workflows/utils.ts had no production callers — the only references were mock entries in @sim/testing that no test consumed. They were a second, less safe implementation of folder writes (no lock check, no audit) shadowing the real one in orchestration/folder-lifecycle.ts. Removing them leaves folder-lifecycle.ts as the single orchestration chokepoint and cuts the live workflow_folder write sites from 15 to 11.
1 parent c77300f commit 2949b3a

2 files changed

Lines changed: 1 addition & 74 deletions

File tree

apps/sim/lib/workflows/utils.ts

Lines changed: 1 addition & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { workflowFolder, workflow as workflowTable } from '@sim/db/schema'
33
import { createLogger } from '@sim/logger'
44
import { authorizeWorkflowByWorkspacePermission } from '@sim/platform-authz/workflow'
55
import { generateId } from '@sim/utils/id'
6-
import { and, asc, eq, inArray, isNull, max, min, sql } from 'drizzle-orm'
6+
import { and, asc, eq, inArray, isNull, min, sql } from 'drizzle-orm'
77
import { NextResponse } from 'next/server'
88
import { getSession } from '@/lib/auth'
99
import { ensureWorkflowAliasBacking } from '@/lib/copilot/vfs/workflow-alias-backing'
@@ -493,45 +493,6 @@ export interface CreateFolderInput {
493493
parentId?: string | null
494494
}
495495

496-
export async function createFolderRecord(params: CreateFolderInput) {
497-
const { userId, workspaceId, name, parentId = null } = params
498-
499-
const [maxResult] = await db
500-
.select({ maxOrder: max(workflowFolder.sortOrder) })
501-
.from(workflowFolder)
502-
.where(
503-
and(
504-
eq(workflowFolder.workspaceId, workspaceId),
505-
parentId ? eq(workflowFolder.parentId, parentId) : isNull(workflowFolder.parentId)
506-
)
507-
)
508-
const sortOrder = (maxResult?.maxOrder ?? 0) + 1
509-
510-
const folderId = generateId()
511-
await db.insert(workflowFolder).values({
512-
id: folderId,
513-
userId,
514-
workspaceId,
515-
parentId,
516-
name,
517-
sortOrder,
518-
createdAt: new Date(),
519-
updatedAt: new Date(),
520-
})
521-
522-
return { folderId, name, workspaceId, parentId }
523-
}
524-
525-
export async function updateFolderRecord(
526-
folderId: string,
527-
updates: { name?: string; parentId?: string | null }
528-
) {
529-
const setData: Record<string, unknown> = { updatedAt: new Date() }
530-
if (updates.name !== undefined) setData.name = updates.name
531-
if (updates.parentId !== undefined) setData.parentId = updates.parentId
532-
await db.update(workflowFolder).set(setData).where(eq(workflowFolder.id, folderId))
533-
}
534-
535496
export async function verifyFolderWorkspace(
536497
folderId: string,
537498
workspaceId: string
@@ -544,34 +505,6 @@ export async function verifyFolderWorkspace(
544505
return Boolean(row)
545506
}
546507

547-
export async function deleteFolderRecord(folderId: string): Promise<boolean> {
548-
const [folder] = await db
549-
.select({ parentId: workflowFolder.parentId })
550-
.from(workflowFolder)
551-
.where(eq(workflowFolder.id, folderId))
552-
.limit(1)
553-
554-
if (!folder) return false
555-
556-
await db
557-
.update(workflowTable)
558-
.set({ folderId: folder.parentId, updatedAt: new Date() })
559-
.where(eq(workflowTable.folderId, folderId))
560-
561-
await db
562-
.update(workflowFolder)
563-
.set({ parentId: folder.parentId, updatedAt: new Date() })
564-
.where(eq(workflowFolder.parentId, folderId))
565-
566-
await db.delete(workflowFolder).where(eq(workflowFolder.id, folderId))
567-
568-
return true
569-
}
570-
571-
/**
572-
* Checks whether setting `parentId` as the parent of `folderId` would
573-
* create a circular reference in the folder tree.
574-
*/
575508
export async function checkForCircularReference(
576509
folderId: string,
577510
parentId: string

packages/testing/src/mocks/workflows-utils.mock.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ export const workflowsUtilsMockFns = {
2424
mockUpdateWorkflowRecord: vi.fn(),
2525
mockDeleteWorkflowRecord: vi.fn(),
2626
mockSetWorkflowVariables: vi.fn(),
27-
mockCreateFolderRecord: vi.fn(),
28-
mockUpdateFolderRecord: vi.fn(),
29-
mockDeleteFolderRecord: vi.fn(),
3027
mockCheckForCircularReference: vi.fn(),
3128
mockListFolders: vi.fn(),
3229
}
@@ -61,9 +58,6 @@ export const workflowsUtilsMock = {
6158
updateWorkflowRecord: workflowsUtilsMockFns.mockUpdateWorkflowRecord,
6259
deleteWorkflowRecord: workflowsUtilsMockFns.mockDeleteWorkflowRecord,
6360
setWorkflowVariables: workflowsUtilsMockFns.mockSetWorkflowVariables,
64-
createFolderRecord: workflowsUtilsMockFns.mockCreateFolderRecord,
65-
updateFolderRecord: workflowsUtilsMockFns.mockUpdateFolderRecord,
66-
deleteFolderRecord: workflowsUtilsMockFns.mockDeleteFolderRecord,
6761
checkForCircularReference: workflowsUtilsMockFns.mockCheckForCircularReference,
6862
listFolders: workflowsUtilsMockFns.mockListFolders,
6963
}

0 commit comments

Comments
 (0)