@@ -43,8 +43,6 @@ import {
43
43
import { htmlToMarkup } from '@hcengineering/text'
44
44
import {
45
45
getAccountUuidByOldAccount ,
46
- getAccountUuidBySocialKey ,
47
- getSocialIdBySocialKey ,
48
46
getSocialIdFromOldAccount ,
49
47
getSocialKeyByOldAccount
50
48
} from '@hcengineering/model-core'
@@ -365,151 +363,6 @@ async function migrateAccountsInDocUpdates (client: MigrationClient): Promise<vo
365
363
ctx . info ( 'finished processing activity doc updates ' , { } )
366
364
}
367
365
368
- /**
369
- * Migrates social ids to new accounts where needed.
370
- * Should only be applied to staging where old accounts have already been migrated to social ids.
371
- * REMOVE IT BEFORE MERGING TO PRODUCTION
372
- * @param client
373
- * @returns
374
- */
375
- async function migrateSocialIdsInDocUpdates ( client : MigrationClient ) : Promise < void > {
376
- const ctx = new MeasureMetricsContext ( 'activity migrateSocialIdsInDocUpdates' , { } )
377
- const accountUuidBySocialKey = new Map < string , AccountUuid | null > ( )
378
- ctx . info ( 'processing activity doc updates ' , { } )
379
-
380
- async function getUpdatedVal ( oldVal : string ) : Promise < any > {
381
- return ( await getAccountUuidBySocialKey ( client , oldVal , accountUuidBySocialKey ) ) ?? oldVal
382
- }
383
-
384
- async function migrateField < P extends keyof DocAttributeUpdates > (
385
- au : DocAttributeUpdates ,
386
- update : MigrateUpdate < DocUpdateMessage > [ 'attributeUpdates' ] ,
387
- field : P
388
- ) : Promise < void > {
389
- const oldValue = au ?. [ field ]
390
- if ( oldValue == null ) return
391
-
392
- let changed = false
393
- let newValue : any
394
- if ( Array . isArray ( oldValue ) ) {
395
- newValue = [ ]
396
- for ( const a of oldValue as any [ ] ) {
397
- const newA = a != null ? await getUpdatedVal ( a ) : a
398
- if ( newA !== a ) {
399
- changed = true
400
- }
401
- newValue . push ( newA )
402
- }
403
- } else {
404
- newValue = await getUpdatedVal ( oldValue )
405
- if ( newValue !== oldValue ) {
406
- changed = true
407
- }
408
- }
409
-
410
- if ( changed ) {
411
- if ( update == null ) throw new Error ( 'update is null' )
412
-
413
- update [ field ] = newValue
414
- }
415
- }
416
-
417
- const iterator = await client . traverse ( DOMAIN_ACTIVITY , {
418
- _class : activity . class . DocUpdateMessage ,
419
- action : 'update' ,
420
- 'attributeUpdates.attrClass' : 'core:class:TypePersonId' ,
421
- 'attributeUpdates.attrKey' : { $in : [ 'members' , 'owners' , 'user' ] }
422
- } )
423
-
424
- try {
425
- let processed = 0
426
- while ( true ) {
427
- const docs = await iterator . next ( 200 )
428
- if ( docs === null || docs . length === 0 ) {
429
- break
430
- }
431
-
432
- const operations : {
433
- filter : MigrationDocumentQuery < DocUpdateMessage >
434
- update : MigrateUpdate < DocUpdateMessage >
435
- } [ ] = [ ]
436
-
437
- for ( const doc of docs ) {
438
- const dum = doc as DocUpdateMessage
439
- if ( dum . attributeUpdates == null ) continue
440
- const update : any = { attributeUpdates : { ...dum . attributeUpdates } }
441
-
442
- await migrateField ( dum . attributeUpdates , update . attributeUpdates , 'added' )
443
- await migrateField ( dum . attributeUpdates , update . attributeUpdates , 'prevValue' )
444
- await migrateField ( dum . attributeUpdates , update . attributeUpdates , 'removed' )
445
- await migrateField ( dum . attributeUpdates , update . attributeUpdates , 'set' )
446
-
447
- update . attributeUpdates . attrClass = core . class . TypeAccountUuid
448
-
449
- operations . push ( {
450
- filter : { _id : dum . _id } ,
451
- update
452
- } )
453
- }
454
-
455
- if ( operations . length > 0 ) {
456
- await client . bulk ( DOMAIN_ACTIVITY , operations )
457
- }
458
-
459
- processed += docs . length
460
- ctx . info ( '...processed' , { count : processed } )
461
- }
462
- } finally {
463
- await iterator . close ( )
464
- }
465
-
466
- ctx . info ( 'finished processing activity doc updates ' , { } )
467
- }
468
-
469
- async function migrateSocialKeysToSocialIds ( client : MigrationClient ) : Promise < void > {
470
- const ctx = new MeasureMetricsContext ( 'activity migrateSocialKeysToSocialIds' , { } )
471
-
472
- ctx . info ( 'processing activity reactions ' , { } )
473
- const socialIdBySocialKey = new Map < string , PersonId | null > ( )
474
- const iterator = await client . traverse ( DOMAIN_REACTION , { _class : activity . class . Reaction } )
475
-
476
- try {
477
- let processed = 0
478
- while ( true ) {
479
- const docs = await iterator . next ( 200 )
480
- if ( docs === null || docs . length === 0 ) {
481
- break
482
- }
483
-
484
- const operations : { filter : MigrationDocumentQuery < Doc > , update : MigrateUpdate < Doc > } [ ] = [ ]
485
-
486
- for ( const doc of docs ) {
487
- const reaction = doc as Reaction
488
- const newCreateBy =
489
- ( await getSocialIdBySocialKey ( client , reaction . createBy , socialIdBySocialKey ) ) ?? reaction . createBy
490
-
491
- if ( newCreateBy === reaction . createBy ) continue
492
-
493
- operations . push ( {
494
- filter : { _id : doc . _id } ,
495
- update : {
496
- createBy : newCreateBy
497
- }
498
- } )
499
- processed ++
500
- }
501
-
502
- if ( operations . length > 0 ) {
503
- await client . bulk ( DOMAIN_REACTION , operations )
504
- ctx . info ( '...processed' , { count : processed } )
505
- }
506
- }
507
- } finally {
508
- await iterator . close ( )
509
- }
510
- ctx . info ( 'finished processing activity reactions ' , { } )
511
- }
512
-
513
366
export const activityOperation : MigrateOperation = {
514
367
async migrate ( client : MigrationClient , mode ) : Promise < void > {
515
368
await tryMigrate ( mode , client , activityId , [
@@ -592,18 +445,6 @@ export const activityOperation: MigrateOperation = {
592
445
state : 'accounts-in-doc-updates-v2' ,
593
446
mode : 'upgrade' ,
594
447
func : migrateAccountsInDocUpdates
595
- } ,
596
- // ONLY FOR STAGING. REMOVE IT BEFORE MERGING TO PRODUCTION
597
- {
598
- state : 'social-ids-in-doc-updates' ,
599
- mode : 'upgrade' ,
600
- func : migrateSocialIdsInDocUpdates
601
- } ,
602
- // ONLY FOR STAGING. REMOVE IT BEFORE MERGING TO PRODUCTION
603
- {
604
- state : 'social-keys-to-social-ids-v2' ,
605
- mode : 'upgrade' ,
606
- func : migrateSocialKeysToSocialIds
607
448
}
608
449
] )
609
450
} ,
0 commit comments