-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JIT Datasources] Create conversations space (#8662)
* create group by default & hide from ux * restriction on v1 routes * restriction on internal routes * unicity constraint * backfill * fix schema * clean * fix enum * flag conv space * fix * lint
- Loading branch information
1 parent
5daeb85
commit fb44741
Showing
52 changed files
with
558 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
front/migrations/20241114_conversations_spaces_backfill.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import _ from "lodash"; | ||
|
||
import { Workspace } from "@app/lib/models/workspace"; | ||
import { GroupResource } from "@app/lib/resources/group_resource"; | ||
import { SpaceResource } from "@app/lib/resources/space_resource"; | ||
import { makeScript } from "@app/scripts/helpers"; | ||
|
||
async function backfillWorkspacesGroup(execute: boolean) { | ||
const workspaces = await Workspace.findAll(); | ||
|
||
const chunks = _.chunk(workspaces, 16); | ||
for (const [i, c] of chunks.entries()) { | ||
console.log( | ||
`[execute=${execute}] Processing chunk of ${c.length} workspaces... (${ | ||
i + 1 | ||
}/${chunks.length})` | ||
); | ||
if (execute) { | ||
await Promise.all( | ||
c.map((w) => | ||
(async () => { | ||
try { | ||
const workspaceGroup = | ||
await GroupResource.internalFetchWorkspaceGlobalGroup(w.id); | ||
if (!workspaceGroup) { | ||
throw new Error("Workspace group not found"); | ||
} | ||
await SpaceResource.makeNew( | ||
{ | ||
name: "Conversations", | ||
kind: "conversations", | ||
workspaceId: w.id, | ||
}, | ||
[workspaceGroup] | ||
); | ||
} catch (error) { | ||
if ( | ||
error instanceof Error && | ||
error.cause && | ||
error.cause === "enforce_one_conversations_space_per_workspace" | ||
) { | ||
console.log( | ||
`Conversation already exists for workspace ${w.id}` | ||
); | ||
} else { | ||
throw error; | ||
} | ||
} | ||
})() | ||
) | ||
); | ||
} | ||
} | ||
|
||
console.log(`Done.`); | ||
} | ||
|
||
makeScript({}, async ({ execute }) => { | ||
await backfillWorkspacesGroup(execute); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.