Skip to content

Commit

Permalink
uberf-6537: fix teamspace creation (#5354)
Browse files Browse the repository at this point in the history
Signed-off-by: Alexey Zinoviev <[email protected]>
  • Loading branch information
lexiv0re authored Apr 15, 2024
1 parent bccf97e commit c123278
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 18 deletions.
7 changes: 5 additions & 2 deletions models/document/src/migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,15 +314,18 @@ export const documentOperation: MigrateOperation = {
},

async upgrade (client: MigrationUpgradeClient): Promise<void> {
const tx = new TxOperations(client, core.account.System)
await tryUpgrade(client, documentId, [
{
state: 'u-default-project',
func: async (client) => {
const tx = new TxOperations(client, core.account.System)
await createSpace(tx)
await createDefaultTeamspaceType(tx)
}
}
])

// Currently space type has to be recreated every time as it's in the model
// created by the system user
await createDefaultTeamspaceType(tx)
}
}
44 changes: 28 additions & 16 deletions models/lead/src/migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,29 @@ async function createSpace (tx: TxOperations): Promise<void> {
_id: lead.space.DefaultFunnel
})
if (current === undefined) {
const type = await createProjectType(
await tx.createDoc(
lead.class.Funnel,
core.space.Space,
{
name: 'Funnel',
description: 'Default funnel',
private: false,
archived: false,
members: [],
type: lead.template.DefaultFunnel
},
lead.space.DefaultFunnel
)
}
}

async function createSpaceType (tx: TxOperations): Promise<void> {
const current = await tx.findOne(task.class.ProjectType, {
_id: lead.template.DefaultFunnel
})

if (current === undefined) {
await createProjectType(
tx,
{
name: 'Default funnel',
Expand Down Expand Up @@ -101,19 +123,6 @@ async function createSpace (tx: TxOperations): Promise<void> {
],
lead.template.DefaultFunnel
)
await tx.createDoc(
lead.class.Funnel,
core.space.Space,
{
name: 'Funnel',
description: 'Default funnel',
private: false,
archived: false,
members: [],
type
},
lead.space.DefaultFunnel
)
}
}

Expand Down Expand Up @@ -179,14 +188,17 @@ export const leadOperation: MigrateOperation = {
])
},
async upgrade (client: MigrationUpgradeClient): Promise<void> {
const ops = new TxOperations(client, core.account.System)
await tryUpgrade(client, leadId, [
{
state: 'u-default-funnel',
func: async (client) => {
const ops = new TxOperations(client, core.account.System)
func: async () => {
await createDefaults(ops)
}
}
])
// Currently space type has to be recreated every time as it's in the model
// created by the system user
await createSpaceType(ops)
}
}

0 comments on commit c123278

Please sign in to comment.