MCPcopy Index your code
hub / github.com/simstudioai/sim / archiveWorkspace

Function archiveWorkspace

apps/sim/lib/workspaces/lifecycle.ts:29–193  ·  view source on GitHub ↗
(
  workspaceId: string,
  options: ArchiveWorkspaceOptions
)

Source from the content-addressed store, hash-verified

27}
28
29export async function archiveWorkspace(
30 workspaceId: string,
31 options: ArchiveWorkspaceOptions
32): Promise<{ archived: boolean; workspaceName?: string }> {
33 const workspaceRecord = await getWorkspaceWithOwner(workspaceId, { includeArchived: true })
34
35 if (!workspaceRecord) {
36 return { archived: false }
37 }
38
39 if (workspaceRecord.archivedAt) {
40 await archiveWorkflowsForWorkspace(workspaceId, options)
41 return { archived: false, workspaceName: workspaceRecord.name }
42 }
43
44 const now = new Date()
45 const workflowMcpServerIds = await db
46 .select({ id: workflowMcpServer.id })
47 .from(workflowMcpServer)
48 .where(eq(workflowMcpServer.workspaceId, workspaceId))
49
50 await db.transaction(async (tx) => {
51 await tx
52 .update(knowledgeBase)
53 .set({
54 deletedAt: now,
55 updatedAt: now,
56 })
57 .where(and(eq(knowledgeBase.workspaceId, workspaceId), isNull(knowledgeBase.deletedAt)))
58
59 const workspaceKbIds = await tx
60 .select({ id: knowledgeBase.id })
61 .from(knowledgeBase)
62 .where(eq(knowledgeBase.workspaceId, workspaceId))
63
64 const knowledgeBaseIds = workspaceKbIds.map((entry) => entry.id)
65 if (knowledgeBaseIds.length > 0) {
66 await tx
67 .update(document)
68 .set({ archivedAt: now })
69 .where(
70 and(
71 inArray(document.knowledgeBaseId, knowledgeBaseIds),
72 isNull(document.archivedAt),
73 isNull(document.deletedAt)
74 )
75 )
76
77 await tx
78 .update(knowledgeConnector)
79 .set({ archivedAt: now, status: 'paused', updatedAt: now })
80 .where(
81 and(
82 inArray(knowledgeConnector.knowledgeBaseId, knowledgeBaseIds),
83 isNull(knowledgeConnector.archivedAt),
84 isNull(knowledgeConnector.deletedAt)
85 )
86 )

Callers 3

lifecycle.test.tsFile · 0.90
route.tsFile · 0.90
disableUserResourcesFunction · 0.85

Calls 8

getWorkspaceWithOwnerFunction · 0.90
infoMethod · 0.80
clearCacheMethod · 0.80
setMethod · 0.65
deleteMethod · 0.65
eqFunction · 0.50

Tested by

no test coverage detected