Qfix: calendar user migration (#9707)

Signed-off-by: Alexey Zinoviev <alexey.zinoviev@xored.com>
This commit is contained in:
Alexey Zinoviev
2025-08-20 23:56:14 +07:00
committed by GitHub
parent 33b597d5b4
commit 5f600e2ff9
+65 -1
View File
@@ -41,7 +41,12 @@ import {
tryMigrate,
tryUpgrade
} from '@hcengineering/model'
import { DOMAIN_SPACE, getAccountUuidBySocialKey, getSocialKeyByOldAccount } from '@hcengineering/model-core'
import {
DOMAIN_SPACE,
getAccountUuidBySocialKey,
getSocialIdFromOldAccount,
getSocialKeyByOldAccount
} from '@hcengineering/model-core'
import setting, { DOMAIN_SETTING, type Integration } from '@hcengineering/setting'
import { DOMAIN_CALENDAR, DOMAIN_EVENT } from '.'
import calendar from './plugin'
@@ -312,6 +317,60 @@ async function fillUser (client: MigrationClient): Promise<void> {
}
}
async function migrateEventUserToNewAccounts (client: MigrationClient): Promise<void> {
const socialKeyByAccount = await getSocialKeyByOldAccount(client)
const socialIdBySocialKey = new Map<string, PersonId | null>()
const socialIdByOldAccount = new Map<string, PersonId | null>()
client.logger.log('processing events user ', {})
const iterator = await client.traverse(DOMAIN_EVENT, {
_class: { $in: [calendar.class.Event, calendar.class.ReccuringEvent] }
})
try {
let processed = 0
while (true) {
const docs = await iterator.next(200)
if (docs === null || docs.length === 0) {
break
}
const operations: { filter: MigrationDocumentQuery<Doc>, update: MigrateUpdate<Doc> }[] = []
for (const doc of docs) {
const event = doc as Event
const socialId = await getSocialIdFromOldAccount(
client,
event.user,
socialKeyByAccount,
socialIdBySocialKey,
socialIdByOldAccount
)
const newUser = socialId ?? event.user
if (newUser === event.user) continue
operations.push({
filter: { _id: doc._id },
update: {
user: newUser
}
})
}
if (operations.length > 0) {
await client.bulk(DOMAIN_EVENT, operations)
}
processed += docs.length
client.logger.log('...processed', { count: processed })
}
} finally {
await iterator.close()
}
client.logger.log('finished processing events user ', {})
}
async function fillBlockTime (client: MigrationClient): Promise<void> {
await client.update(DOMAIN_EVENT, { blockTime: { $exists: false }, allDay: true }, { blockTime: false })
await client.update(DOMAIN_EVENT, { blockTime: { $exists: false } }, { blockTime: true })
@@ -391,6 +450,11 @@ export const calendarOperation: MigrateOperation = {
state: 'fill-calendar-user-and-access',
mode: 'upgrade',
func: fillCalendarUserAndAccess
},
{
state: 'migrate-ev-user-to-new-accounts',
mode: 'upgrade',
func: migrateEventUserToNewAccounts
}
])
},