You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ctx.info(` Processing the whole table ${tableName}...`)
832
+
awaitpgClient`
833
+
UPDATE ${pgClient(tableName)}
834
+
SET "createdBy" = m.correct_person_id::text
835
+
FROM temp_data.account_personid_mapping_fixed m
836
+
WHERE ${pgClient(tableName)}."workspaceId" = ${wsUuid} AND ${pgClient(tableName)}."workspaceId" = m.workspace_id AND ${pgClient(tableName)}."createdBy" = m.current_person_id
837
+
`
838
+
progressMade=true
839
+
}else{
840
+
ctx.info(` Processing the table ${tableName} in batches of ${batchSize}...`)
841
+
letprocessed=0
842
+
while(true){
843
+
constres=awaitpgClient`
844
+
UPDATE ${pgClient(tableName)}
845
+
SET "createdBy" = m.correct_person_id::text
846
+
FROM temp_data.account_personid_mapping_fixed m
847
+
WHERE ${pgClient(tableName)}."workspaceId" = ${wsUuid} AND ${pgClient(tableName)}."workspaceId" = m.workspace_id AND ${pgClient(tableName)}."createdBy" = m.current_person_id
848
+
LIMIT ${batchSize}
849
+
`
850
+
progressMade=true
851
+
if(res.count===0){
852
+
break
853
+
}
854
+
processed+=res.count
855
+
constduration=(Date.now()-startTime)/1000
856
+
constrate=Math.round(processed/duration)
857
+
ctx.info(
858
+
` Processing createdBy for ${tableName}: ${processed} rows in ${duration}s (${rate} rows/sec)`
859
+
)
860
+
}
861
+
}
862
+
863
+
awaitpgClient`INSERT INTO temp_data.account_personid_mapping_fixed_progress (workspace_id, domain, field) VALUES (${wsUuid}, ${tableName}, 'createdBy') ON CONFLICT DO NOTHING`
` Updated createdBy for ${tableName}: ${createdByCount.count} rows in ${duration}s (${rate} rows/sec)`
869
+
)
870
+
}else{
871
+
if(createdDone){
872
+
ctx.info(' Skipping createdBy for table. Already done',{ tableName })
873
+
}else{
874
+
awaitpgClient`INSERT INTO temp_data.account_personid_mapping_fixed_progress (workspace_id, domain, field) VALUES (${wsUuid}, ${tableName}, 'createdBy') ON CONFLICT DO NOTHING`
875
+
}
876
+
}
877
+
878
+
if(modifiedByCount.count>0){
879
+
ctx.info(` Updating modifiedBy for ${tableName}...`)
ctx.info(` Processing the whole table ${tableName}...`)
884
+
awaitpgClient`
885
+
UPDATE ${pgClient(tableName)}
886
+
SET "modifiedBy" = m.correct_person_id::text
887
+
FROM temp_data.account_personid_mapping_fixed m
888
+
WHERE ${pgClient(tableName)}."workspaceId" = ${wsUuid} AND ${pgClient(tableName)}."workspaceId" = m.workspace_id AND ${pgClient(tableName)}."modifiedBy" = m.current_person_id
889
+
`
890
+
progressMade=true
891
+
}else{
892
+
ctx.info(` Processing the table ${tableName} in batches of ${batchSize}...`)
893
+
letprocessed=0
894
+
while(true){
895
+
constres=awaitpgClient`
896
+
UPDATE ${pgClient(tableName)}
897
+
SET "modifiedBy" = m.correct_person_id::text
898
+
FROM temp_data.account_personid_mapping_fixed m
899
+
WHERE ${pgClient(tableName)}."workspaceId" = ${wsUuid} AND ${pgClient(tableName)}."workspaceId" = m.workspace_id AND ${pgClient(tableName)}."modifiedBy" = m.current_person_id
900
+
LIMIT ${batchSize}
901
+
`
902
+
progressMade=true
903
+
if(res.count===0){
904
+
break
905
+
}
906
+
processed+=res.count
907
+
constduration=(Date.now()-startTime)/1000
908
+
constrate=Math.round(processed/duration)
909
+
ctx.info(
910
+
` Processing modifiedBy for ${tableName}: ${processed} rows in ${duration}s (${rate} rows/sec)`
911
+
)
912
+
}
913
+
}
914
+
915
+
awaitpgClient`INSERT INTO temp_data.account_personid_mapping_fixed_progress (workspace_id, domain, field) VALUES (${wsUuid}, ${tableName}, 'modifiedBy') ON CONFLICT DO NOTHING`
` Updated modifiedBy for ${tableName}: ${modifiedByCount.count} rows in ${duration}s (${rate} rows/sec)`
921
+
)
922
+
}else{
923
+
if(modifiedDone){
924
+
ctx.info(' Skipping modifiedBy for table. Already done',{ tableName })
925
+
}else{
926
+
awaitpgClient`INSERT INTO temp_data.account_personid_mapping_fixed_progress (workspace_id, domain, field) VALUES (${wsUuid}, ${tableName}, 'modifiedBy') ON CONFLICT DO NOTHING`
927
+
}
928
+
}
929
+
}
930
+
931
+
done=true
932
+
ctx.info('Migration of created/modified completed successfully')
933
+
}catch(err: any){
934
+
if(err.code==='40001'||err.code==='55P03'){
935
+
// Retry transaction
936
+
if(retriesCount===maxRetries){
937
+
ctx.error('Failed to migrate created/modified by. Max retries reached',{ err })
938
+
}else{
939
+
retrying=true
940
+
continue
941
+
}
942
+
}
943
+
944
+
if(err.code==='CONNECTION_CLOSED'){
945
+
// Reconnect
946
+
ctx.info(' Connection closed...')
947
+
if(connectsCount===maxReconnects){
948
+
ctx.error('Failed to migrate created/modified by. Max reconnects reached',{ err })
949
+
}else{
950
+
reconnecting=true
951
+
continue
952
+
}
953
+
}
954
+
955
+
throwerr
956
+
}finally{
957
+
pg?.close()
958
+
}
959
+
}
960
+
961
+
if(!done){
962
+
ctx.error('Failed to migrate created/modified by')
0 commit comments