uberf-10626: fix social identity duplicate key exception (#8969)

Signed-off-by: Alexey Zinoviev <alexey.zinoviev@xored.com>
This commit is contained in:
Alexey Zinoviev 2025-05-16 14:32:03 +04:00 committed by GitHub
parent 04b01acad0
commit 16f7dfc24a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -459,6 +459,33 @@ async function createUserProfiles (client: MigrationClient): Promise<void> {
}
}
async function fixSocialIdCase (client: MigrationClient): Promise<void> {
const ctx = new MeasureMetricsContext('contact fixSocialIdCase', {})
ctx.info('Fixing social id case...')
const socialIds = await client.traverse<SocialIdentity>(DOMAIN_CHANNEL, {
_class: contact.class.SocialIdentity
})
let updated = 0
while (true) {
const docs = await socialIds.next(200)
if (docs === null || docs?.length === 0) {
break
}
for (const d of docs) {
const newKey = d.key.toLowerCase()
const newVal = d.value.toLowerCase()
if (newKey !== d.key || newVal !== d.value) {
await client.update(DOMAIN_CHANNEL, { _id: d._id }, { key: newKey, value: newVal })
updated++
}
}
}
ctx.info('Finished fixing social id case. Total updated:', { updated })
}
export const contactOperation: MigrateOperation = {
async preMigrate (client: MigrationClient, logger: ModelLogger, mode): Promise<void> {
await tryMigrate(mode, client, contactId, [
@ -640,6 +667,11 @@ export const contactOperation: MigrateOperation = {
state: 'create-user-profiles',
mode: 'upgrade',
func: createUserProfiles
},
{
state: 'fix-social-id-case',
mode: 'upgrade',
func: fixSocialIdCase
}
])
},