Skip to content

Commit cbabc16

Browse files
waleedlatif1claude
andcommitted
fix(workflows): clear folderId on restore when folder is archived or missing
When individually restoring a workflow from Recently Deleted, check if its folder still exists and is active. If the folder is archived or missing, clear folderId so the workflow appears at root instead of being orphaned (invisible in sidebar). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 690508a commit cbabc16

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

apps/sim/lib/workflows/lifecycle.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
webhook,
77
workflow,
88
workflowDeploymentVersion,
9+
workflowFolder,
910
workflowMcpTool,
1011
workflowSchedule,
1112
} from '@sim/db/schema'
@@ -258,12 +259,28 @@ export async function restoreWorkflow(
258259
}
259260
}
260261

262+
let clearFolderId = false
263+
if (existingWorkflow.folderId) {
264+
const [folder] = await db
265+
.select({ archivedAt: workflowFolder.archivedAt })
266+
.from(workflowFolder)
267+
.where(eq(workflowFolder.id, existingWorkflow.folderId))
268+
269+
if (!folder || folder.archivedAt) {
270+
clearFolderId = true
271+
}
272+
}
273+
261274
const now = new Date()
262275

263276
await db.transaction(async (tx) => {
264277
await tx
265278
.update(workflow)
266-
.set({ archivedAt: null, updatedAt: now })
279+
.set({
280+
archivedAt: null,
281+
updatedAt: now,
282+
...(clearFolderId && { folderId: null }),
283+
})
267284
.where(eq(workflow.id, workflowId))
268285

269286
await tx

0 commit comments

Comments
 (0)