diff --git a/dev/tool/src/clean.ts b/dev/tool/src/clean.ts index a4f3ae5921..00978bf78d 100644 --- a/dev/tool/src/clean.ts +++ b/dev/tool/src/clean.ts @@ -41,10 +41,7 @@ import recruitModel from '@hcengineering/model-recruit' import { type StorageAdapter } from '@hcengineering/server-core' import { connect } from '@hcengineering/server-tool' import tags, { type TagCategory, type TagElement, type TagReference } from '@hcengineering/tags' -import task, { - type ProjectType, - type TaskType -} from '@hcengineering/task' +import task, { type ProjectType, type TaskType } from '@hcengineering/task' import tracker from '@hcengineering/tracker' import { deepEqual } from 'fast-equals' import { MongoClient } from 'mongodb' diff --git a/models/lead/src/migration.ts b/models/lead/src/migration.ts index 519079c9d3..c11c7b2685 100644 --- a/models/lead/src/migration.ts +++ b/models/lead/src/migration.ts @@ -148,7 +148,7 @@ async function migrateDefaultTypeMixins (client: MigrationClient): Promise } export const leadOperation: MigrateOperation = { - async preMigrate (client: MigrationClient, logger: ModelLogger): Promise { + async preMigrate (client: MigrationClient, logger: ModelLogger): Promise { await tryMigrate(client, leadId, [ { state: 'migrate-default-statuses', diff --git a/models/recruit/src/migration.ts b/models/recruit/src/migration.ts index 0cb84680f5..7c53946c2c 100644 --- a/models/recruit/src/migration.ts +++ b/models/recruit/src/migration.ts @@ -33,7 +33,7 @@ import { DOMAIN_SPACE } from '@hcengineering/model-core' import { defaultApplicantStatuses } from './spaceType' export const recruitOperation: MigrateOperation = { - async preMigrate (client: MigrationClient, logger: ModelLogger): Promise { + async preMigrate (client: MigrationClient, logger: ModelLogger): Promise { await tryMigrate(client, recruitId, [ { state: 'migrate-default-statuses', diff --git a/models/task/src/migration.ts b/models/task/src/migration.ts index 5a05204db7..255b5c4a51 100644 --- a/models/task/src/migration.ts +++ b/models/task/src/migration.ts @@ -13,7 +13,20 @@ // limitations under the License. // -import { type Attribute, type Space, type Status, type TxCreateDoc, TxOperations, type Class, type Doc, type Ref, DOMAIN_TX, DOMAIN_STATUS, type TxUpdateDoc, type TxCollectionCUD } from '@hcengineering/core' +import { + type Attribute, + type Space, + type Status, + type TxCreateDoc, + TxOperations, + type Class, + type Doc, + type Ref, + DOMAIN_TX, + DOMAIN_STATUS, + type TxUpdateDoc, + type TxCollectionCUD +} from '@hcengineering/core' import { type ModelLogger, createOrUpdate, @@ -27,7 +40,14 @@ import activity, { type DocUpdateMessage } from '@hcengineering/activity' import { DOMAIN_ACTIVITY } from '@hcengineering/model-activity' import core, { DOMAIN_SPACE } from '@hcengineering/model-core' import tags from '@hcengineering/model-tags' -import { type ProjectType, type ProjectTypeDescriptor, type Task, type TaskType, taskId, type ProjectStatus } from '@hcengineering/task' +import { + type ProjectType, + type ProjectTypeDescriptor, + type Task, + type TaskType, + taskId, + type ProjectStatus +} from '@hcengineering/task' import task from './plugin' import { DOMAIN_TASK } from '.' @@ -124,7 +144,7 @@ export async function migrateDefaultStatusesBase ( if (defaultTypes.length === 2) { logger.log('Are you running the tool after the workspace has been upgraded?', '') - logger.log('NOT SUPPORTED. EXITING.', '') + logger.error('NOT SUPPORTED. EXITING.', '') return } else if (defaultTypes.length === 0) { logger.log('No default type found. Was custom and already migrated? Nothing to do.', '') @@ -140,17 +160,20 @@ export async function migrateDefaultStatusesBase ( // Can only move to system if the task is with the system id // and not modified by user if (defaultType.attributes.tasks.length === 1 && defaultType.attributes.tasks[0] === defaultTaskTypeId) { - const defaultTaskType = (await client.find>(DOMAIN_TX, { - _class: core.class.TxCreateDoc, - objectId: defaultTaskTypeId, - objectSpace: core.space.Model, - 'attributes.parent': defaultTypeId - }))[0] + const defaultTaskType = ( + await client.find>(DOMAIN_TX, { + _class: core.class.TxCreateDoc, + objectId: defaultTaskTypeId, + objectSpace: core.space.Model, + 'attributes.parent': defaultTypeId + }) + )[0] if (defaultTaskType?.modifiedBy === core.account.ConfigUser) { logger.log('Moving the existing default type created by ConfigUser to a system one', '') logger.log('Moving the existing default task type created by ConfigUser to a system one', '') - await client.update(DOMAIN_TX, + await client.update( + DOMAIN_TX, { _id: defaultTaskType._id }, { $set: { @@ -159,7 +182,8 @@ export async function migrateDefaultStatusesBase ( } ) - await client.update(DOMAIN_TX, + await client.update( + DOMAIN_TX, { _id: defaultType._id }, { $set: { @@ -169,7 +193,7 @@ export async function migrateDefaultStatusesBase ( ) } else if (defaultTaskType?.modifiedBy !== core.account.System) { logger.log('Default task type has been modified by user.', '') - logger.log('NOT SUPPORTED. EXITING.', '') + logger.error('NOT SUPPORTED. EXITING.', '') return } } else { @@ -182,13 +206,14 @@ export async function migrateDefaultStatusesBase ( // Update to use the new ID of the type if no default task type if (defaultType.attributes.tasks.includes(defaultTaskTypeId)) { logger.log('Default type has been modified by user and it contains default task type', '') - logger.log('NOT SUPPORTED. EXITING.', '') + logger.error('NOT SUPPORTED. EXITING.', '') return } logger.log('Moving the existing default type to a custom one', '') const newId = defaultType.objectId + '-custom' - await client.update(DOMAIN_TX, + await client.update( + DOMAIN_TX, { _id: defaultType._id }, { $set: { @@ -197,7 +222,8 @@ export async function migrateDefaultStatusesBase ( } } ) - await client.update(DOMAIN_TX, + await client.update( + DOMAIN_TX, { objectId: defaultType.objectId, objectSpace: core.space.Model @@ -208,7 +234,8 @@ export async function migrateDefaultStatusesBase ( } } ) - await client.update(DOMAIN_TX, + await client.update( + DOMAIN_TX, { objectId: { $in: defaultType.attributes.tasks }, objectSpace: core.space.Model, @@ -220,7 +247,8 @@ export async function migrateDefaultStatusesBase ( } } ) - await client.update(DOMAIN_SPACE, + await client.update( + DOMAIN_SPACE, { _class: baseClass, type: defaultTypeId @@ -425,7 +453,11 @@ export async function migrateDefaultStatusesBase ( } counter++ - await client.update(DOMAIN_TX, { _id: ttsUpdate._id }, { $set: { 'operations.statuses': newTaskTypeUpdateStatuses } }) + await client.update( + DOMAIN_TX, + { _id: ttsUpdate._id }, + { $set: { 'operations.statuses': newTaskTypeUpdateStatuses } } + ) } logger.log('allTaskTypeStatusesUpdates updated: ', counter) @@ -514,7 +546,11 @@ export async function migrateDefaultStatusesBase ( if (statusSet !== newStatusSet) { counter++ - await client.update(DOMAIN_ACTIVITY, { _id: updateMessage._id }, { $set: { 'attributeUpdates.set.0': newStatusSet } }) + await client.update( + DOMAIN_ACTIVITY, + { _id: updateMessage._id }, + { $set: { 'attributeUpdates.set.0': newStatusSet } } + ) } } logger.log('Base task update messages updated: ', counter) diff --git a/models/tracker/src/migration.ts b/models/tracker/src/migration.ts index 93aec9422d..740380115b 100644 --- a/models/tracker/src/migration.ts +++ b/models/tracker/src/migration.ts @@ -38,7 +38,14 @@ import { DOMAIN_ACTIVITY } from '@hcengineering/model-activity' import { DOMAIN_TASK, migrateDefaultStatusesBase } from '@hcengineering/model-task' import tags from '@hcengineering/tags' import task from '@hcengineering/task' -import { type IssueStatus, TimeReportDayType, trackerId, type Issue, type Project, classicIssueTaskStatuses } from '@hcengineering/tracker' +import { + type IssueStatus, + TimeReportDayType, + trackerId, + type Issue, + type Project, + classicIssueTaskStatuses +} from '@hcengineering/tracker' import tracker from './plugin' async function createDefaultProject (tx: TxOperations): Promise { @@ -210,7 +217,11 @@ async function migrateDefaultStatuses (client: MigrationClient, logger: ModelLog const newStatusSet = statusSet != null ? getNewStatus(statusSet as Ref) : statusSet if (statusSet !== newStatusSet) { - await client.update(DOMAIN_ACTIVITY, { _id: updateMessage._id }, { $set: { 'attributeUpdates.set.0': newStatusSet } }) + await client.update( + DOMAIN_ACTIVITY, + { _id: updateMessage._id }, + { $set: { 'attributeUpdates.set.0': newStatusSet } } + ) } } } @@ -322,7 +333,7 @@ async function migrateDefaultTypeMixins (client: MigrationClient): Promise } export const trackerOperation: MigrateOperation = { - async preMigrate (client: MigrationClient, logger: ModelLogger): Promise { + async preMigrate (client: MigrationClient, logger: ModelLogger): Promise { await tryMigrate(client, trackerId, [ { state: 'migrate-default-statuses', diff --git a/server/tool/src/index.ts b/server/tool/src/index.ts index 87de8680aa..27ac472583 100644 --- a/server/tool/src/index.ts +++ b/server/tool/src/index.ts @@ -212,7 +212,12 @@ export async function upgradeModel ( const db = getWorkspaceDB(client, workspaceId) const prevModel = await fetchModelFromMongo(ctx, mongodbUri, workspaceId) - const { migrateClient: preMigrateClient } = await prepareMigrationClient(db, prevModel.hierarchy, prevModel.modelDb, logger) + const { migrateClient: preMigrateClient } = await prepareMigrationClient( + db, + prevModel.hierarchy, + prevModel.modelDb, + logger + ) await progress(0) await ctx.with('pre-migrate', {}, async () => { @@ -329,10 +334,15 @@ export async function upgradeModel ( } } -async function prepareMigrationClient (db: Db, hierarchy: Hierarchy, model: ModelDb, logger: ModelLogger): Promise<{ - migrateClient: MigrateClientImpl - migrateState: Map> -}> { +async function prepareMigrationClient ( + db: Db, + hierarchy: Hierarchy, + model: ModelDb, + logger: ModelLogger +): Promise<{ + migrateClient: MigrateClientImpl + migrateState: Map> + }> { const migrateClient = new MigrateClientImpl(db, hierarchy, model, logger) const states = await migrateClient.find(DOMAIN_MIGRATION, { _class: core.class.MigrationState }) const sts = Array.from(groupByArray(states, (it) => it.plugin).entries())