diff --git a/models/board/src/migration.ts b/models/board/src/migration.ts index 724a0825fb..77ab705978 100644 --- a/models/board/src/migration.ts +++ b/models/board/src/migration.ts @@ -14,7 +14,7 @@ // import { type Card, boardId } from '@hcengineering/board' -import { type Ref, TxOperations } from '@hcengineering/core' +import { TxOperations } from '@hcengineering/core' import { type MigrateOperation, type MigrationClient, @@ -26,7 +26,7 @@ import { import core, { DOMAIN_SPACE } from '@hcengineering/model-core' import { DOMAIN_TASK, createProjectType, createSequence, fixTaskTypes } from '@hcengineering/model-task' import tags from '@hcengineering/tags' -import task, { type ProjectType } from '@hcengineering/task' +import task from '@hcengineering/task' import { PaletteColorIndexes } from '@hcengineering/ui/src/colors' import board from './plugin' @@ -34,8 +34,8 @@ async function createSpace (tx: TxOperations): Promise { const current = await tx.findOne(core.class.Space, { _id: board.space.DefaultBoard }) + if (current === undefined) { - const defaultType = await createDefaultProjectType(tx) await tx.createDoc( board.class.Board, core.space.Space, @@ -45,15 +45,24 @@ async function createSpace (tx: TxOperations): Promise { private: false, archived: false, members: [], - type: defaultType + type: board.template.DefaultBoard }, board.space.DefaultBoard ) } } -async function createDefaultProjectType (tx: TxOperations): Promise> { - return await createProjectType( +async function createDefaultProjectType (tx: TxOperations): Promise { + const existing = await tx.findOne(task.class.ProjectType, { _id: board.template.DefaultBoard }) + const existingDeleted = await tx.findOne(core.class.TxRemoveDoc, { + objectId: board.template.DefaultBoard + }) + + if (existing !== undefined || existingDeleted !== undefined) { + return + } + + await createProjectType( tx, { name: 'Default board', @@ -185,11 +194,14 @@ export const boardOperation: MigrateOperation = { ]) }, async upgrade (client: MigrationUpgradeClient): Promise { + const ops = new TxOperations(client, core.account.System) + // For now need to be created every time as it's system model + await createDefaultProjectType(ops) + await tryUpgrade(client, boardId, [ { state: 'board0001', - func: async (client) => { - const ops = new TxOperations(client, core.account.System) + func: async () => { await createDefaults(ops) } } diff --git a/models/document/src/migration.ts b/models/document/src/migration.ts index e1b99379a8..24fd4d7bca 100644 --- a/models/document/src/migration.ts +++ b/models/document/src/migration.ts @@ -315,6 +315,10 @@ export const documentOperation: MigrateOperation = { async upgrade (client: MigrationUpgradeClient): Promise { const tx = new TxOperations(client, core.account.System) + // Currently space type has to be recreated every time as it's in the model + // created by the system user + await createDefaultTeamspaceType(tx) + await tryUpgrade(client, documentId, [ { state: 'u-default-project', @@ -323,9 +327,5 @@ export const documentOperation: MigrateOperation = { } } ]) - - // Currently space type has to be recreated every time as it's in the model - // created by the system user - await createDefaultTeamspaceType(tx) } } diff --git a/models/lead/src/migration.ts b/models/lead/src/migration.ts index df927bdfcc..10d0203f59 100644 --- a/models/lead/src/migration.ts +++ b/models/lead/src/migration.ts @@ -189,6 +189,10 @@ export const leadOperation: MigrateOperation = { }, async upgrade (client: MigrationUpgradeClient): Promise { const ops = new TxOperations(client, core.account.System) + // Currently space type has to be recreated every time as it's in the model + // created by the system user + await createSpaceType(ops) + await tryUpgrade(client, leadId, [ { state: 'u-default-funnel', @@ -197,8 +201,5 @@ export const leadOperation: MigrateOperation = { } } ]) - // Currently space type has to be recreated every time as it's in the model - // created by the system user - await createSpaceType(ops) } } diff --git a/models/recruit/src/migration.ts b/models/recruit/src/migration.ts index 3dff487151..bf4e5a52d6 100644 --- a/models/recruit/src/migration.ts +++ b/models/recruit/src/migration.ts @@ -75,11 +75,14 @@ export const recruitOperation: MigrateOperation = { ]) }, async upgrade (client: MigrationUpgradeClient): Promise { + const tx = new TxOperations(client, core.account.System) + // For now need to be created every time as it's system model + await createDefaultKanbanTemplate(tx) + await tryUpgrade(client, recruitId, [ { state: 'create-default-project', func: async (client) => { - const tx = new TxOperations(client, core.account.System) await createDefaults(tx) } }, @@ -150,7 +153,6 @@ async function createDefaults (tx: TxOperations): Promise { await createSequence(tx, recruit.class.Opinion) await createSequence(tx, recruit.class.Applicant) await createSequence(tx, recruit.class.Vacancy) - await createDefaultKanbanTemplate(tx) } async function createDefaultKanbanTemplate (tx: TxOperations): Promise> { diff --git a/models/tracker/src/migration.ts b/models/tracker/src/migration.ts index 44952dfc23..8686372032 100644 --- a/models/tracker/src/migration.ts +++ b/models/tracker/src/migration.ts @@ -61,36 +61,6 @@ async function createDefaultProject (tx: TxOperations): Promise { objectId: tracker.project.DefaultProject }) - if ((await tx.findOne(task.class.ProjectType, { _id: tracker.ids.ClassingProjectType })) === undefined) { - const states: Omit, 'rank'>[] = createStatesData(classicIssueTaskStatuses) - await createProjectType( - tx, - { - name: 'Classic project', - descriptor: tracker.descriptors.ProjectType, - description: '', - tasks: [], - roles: 0, - classic: true - }, - [ - { - _id: tracker.taskTypes.Issue, - descriptor: tracker.descriptors.Issue, - name: 'Issue', - factory: states, - ofClass: tracker.class.Issue, - targetClass: tracker.class.Issue, - statusCategories: classicIssueTaskStatuses.map((it) => it.category), - statusClass: core.class.Status, - kind: 'both', - allowedAsChildOf: [tracker.taskTypes.Issue] - } - ], - tracker.ids.ClassingProjectType - ) - } - // temporary disabled until nice automation // if ((await tx.findOne(task.class.ProjectType, { _id: tracker.ids.BaseProjectType })) === undefined) { // const issueId: Ref = generateId() @@ -154,6 +124,43 @@ async function createDefaultProject (tx: TxOperations): Promise { } } +async function createDefaultProjectType (tx: TxOperations): Promise { + const existing = await tx.findOne(task.class.ProjectType, { _id: tracker.ids.ClassingProjectType }) + const existingDeleted = await tx.findOne(core.class.TxRemoveDoc, { + objectId: tracker.ids.ClassingProjectType + }) + + if (existing === undefined && existingDeleted === undefined) { + const states: Omit, 'rank'>[] = createStatesData(classicIssueTaskStatuses) + await createProjectType( + tx, + { + name: 'Classic project', + descriptor: tracker.descriptors.ProjectType, + description: '', + tasks: [], + roles: 0, + classic: true + }, + [ + { + _id: tracker.taskTypes.Issue, + descriptor: tracker.descriptors.Issue, + name: 'Issue', + factory: states, + ofClass: tracker.class.Issue, + targetClass: tracker.class.Issue, + statusCategories: classicIssueTaskStatuses.map((it) => it.category), + statusClass: core.class.Status, + kind: 'both', + allowedAsChildOf: [tracker.taskTypes.Issue] + } + ], + tracker.ids.ClassingProjectType + ) + } +} + async function createDefaults (tx: TxOperations): Promise { await createDefaultProject(tx) await createOrUpdate( @@ -644,11 +651,14 @@ export const trackerOperation: MigrateOperation = { ]) }, async upgrade (client: MigrationUpgradeClient): Promise { + const tx = new TxOperations(client, core.account.System) + // For now need to be created every time as it's system model + await createDefaultProjectType(tx) + await tryUpgrade(client, trackerId, [ { state: 'create-defaults', - func: async (client) => { - const tx = new TxOperations(client, core.account.System) + func: async () => { await createDefaults(tx) } }