Skip to content

Commit

Permalink
uberf-6576: fix formatting
Browse files Browse the repository at this point in the history
Signed-off-by: Alexey Zinoviev <alexey.zinoviev@xored.com>

Signed-off-by: Alexey Zinoviev <alexey.zinoviev@xored.com>
  • Loading branch information
lexiv0re committed May 3, 2024
1 parent 95c7579 commit a88452c
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 33 deletions.
5 changes: 1 addition & 4 deletions dev/tool/src/clean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion models/lead/src/migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ async function migrateDefaultTypeMixins (client: MigrationClient): Promise<void>
}

export const leadOperation: MigrateOperation = {
async preMigrate (client: MigrationClient, logger: ModelLogger): Promise<void> {
async preMigrate (client: MigrationClient, logger: ModelLogger): Promise<void> {
await tryMigrate(client, leadId, [
{
state: 'migrate-default-statuses',
Expand Down
2 changes: 1 addition & 1 deletion models/recruit/src/migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
async preMigrate (client: MigrationClient, logger: ModelLogger): Promise<void> {
await tryMigrate(client, recruitId, [
{
state: 'migrate-default-statuses',
Expand Down
74 changes: 55 additions & 19 deletions models/task/src/migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 '.'

Expand Down Expand Up @@ -124,7 +144,7 @@ export async function migrateDefaultStatusesBase<T extends Task> (

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.', '')
Expand All @@ -140,17 +160,20 @@ export async function migrateDefaultStatusesBase<T extends Task> (
// 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<TxCreateDoc<TaskType>>(DOMAIN_TX, {
_class: core.class.TxCreateDoc,
objectId: defaultTaskTypeId,
objectSpace: core.space.Model,
'attributes.parent': defaultTypeId
}))[0]
const defaultTaskType = (
await client.find<TxCreateDoc<TaskType>>(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: {
Expand All @@ -159,7 +182,8 @@ export async function migrateDefaultStatusesBase<T extends Task> (
}
)

await client.update(DOMAIN_TX,
await client.update(
DOMAIN_TX,
{ _id: defaultType._id },
{
$set: {
Expand All @@ -169,7 +193,7 @@ export async function migrateDefaultStatusesBase<T extends Task> (
)
} 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 {
Expand All @@ -182,13 +206,14 @@ export async function migrateDefaultStatusesBase<T extends Task> (
// 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: {
Expand All @@ -197,7 +222,8 @@ export async function migrateDefaultStatusesBase<T extends Task> (
}
}
)
await client.update(DOMAIN_TX,
await client.update(
DOMAIN_TX,
{
objectId: defaultType.objectId,
objectSpace: core.space.Model
Expand All @@ -208,7 +234,8 @@ export async function migrateDefaultStatusesBase<T extends Task> (
}
}
)
await client.update(DOMAIN_TX,
await client.update(
DOMAIN_TX,
{
objectId: { $in: defaultType.attributes.tasks },
objectSpace: core.space.Model,
Expand All @@ -220,7 +247,8 @@ export async function migrateDefaultStatusesBase<T extends Task> (
}
}
)
await client.update(DOMAIN_SPACE,
await client.update(
DOMAIN_SPACE,
{
_class: baseClass,
type: defaultTypeId
Expand Down Expand Up @@ -425,7 +453,11 @@ export async function migrateDefaultStatusesBase<T extends Task> (
}

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)

Expand Down Expand Up @@ -514,7 +546,11 @@ export async function migrateDefaultStatusesBase<T extends Task> (

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)
Expand Down
17 changes: 14 additions & 3 deletions models/tracker/src/migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
Expand Down Expand Up @@ -210,7 +217,11 @@ async function migrateDefaultStatuses (client: MigrationClient, logger: ModelLog
const newStatusSet = statusSet != null ? getNewStatus(statusSet as Ref<Status>) : 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 } }
)
}
}
}
Expand Down Expand Up @@ -322,7 +333,7 @@ async function migrateDefaultTypeMixins (client: MigrationClient): Promise<void>
}

export const trackerOperation: MigrateOperation = {
async preMigrate (client: MigrationClient, logger: ModelLogger): Promise<void> {
async preMigrate (client: MigrationClient, logger: ModelLogger): Promise<void> {
await tryMigrate(client, trackerId, [
{
state: 'migrate-default-statuses',
Expand Down
20 changes: 15 additions & 5 deletions server/tool/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -329,10 +334,15 @@ export async function upgradeModel (
}
}

async function prepareMigrationClient (db: Db, hierarchy: Hierarchy, model: ModelDb, logger: ModelLogger): Promise<{
migrateClient: MigrateClientImpl
migrateState: Map<string, Set<string>>
}> {
async function prepareMigrationClient (
db: Db,
hierarchy: Hierarchy,
model: ModelDb,
logger: ModelLogger
): Promise<{
migrateClient: MigrateClientImpl
migrateState: Map<string, Set<string>>
}> {
const migrateClient = new MigrateClientImpl(db, hierarchy, model, logger)
const states = await migrateClient.find<MigrationState>(DOMAIN_MIGRATION, { _class: core.class.MigrationState })
const sts = Array.from(groupByArray(states, (it) => it.plugin).entries())
Expand Down

0 comments on commit a88452c

Please sign in to comment.