@@ -14,9 +14,10 @@ const esClient = helper.getEsClient()
1414/*
1515 * Migrate records from DB to ES
1616 * @param tableName {String} DynamoDB table name
17+ * @param customFunction {Function} custom function to handle record
1718 * @returns {Promise }
1819 */
19- function * migrateRecords ( tableName ) {
20+ function * migrateRecords ( tableName , customFunction ) {
2021 let body = [ ]
2122 let batchCounter = 1
2223 const params = {
@@ -27,7 +28,8 @@ function * migrateRecords (tableName) {
2728 const records = yield dbhelper . scanRecords ( params )
2829 logger . debug ( `Number of ${ tableName } s currently fetched from DB - ` + records . Items . length )
2930 let i = 0
30- for ( const item of records . Items ) {
31+ for ( const recordItem of records . Items ) {
32+ const item = customFunction ( recordItem )
3133 // action
3234 body . push ( {
3335 index : {
@@ -69,12 +71,24 @@ function * migrateRecords (tableName) {
6971
7072co ( function * ( ) {
7173 const promises = [ ]
72- promises . push ( migrateRecords ( 'ReviewType' ) )
73- promises . push ( migrateRecords ( 'Submission' ) )
74- promises . push ( migrateRecords ( 'Review' ) )
75- promises . push ( migrateRecords ( 'ReviewSummation' ) )
74+ const reviews = [ ]
75+ const reviewSummations = [ ]
76+ promises . push ( migrateRecords ( 'ReviewType' , t => t ) )
77+ promises . push ( migrateRecords ( 'Review' , t => {
78+ reviews . push ( t )
79+ return t
80+ } ) )
81+ promises . push ( migrateRecords ( 'ReviewSummation' , t => {
82+ reviewSummations . push ( t )
83+ return t
84+ } ) )
7685 // Process migration in parallel
7786 yield promises
87+ yield migrateRecords ( 'Submission' , t => {
88+ t . review = _ . map ( _ . filter ( reviews , [ 'submissionId' , t . id ] ) , r => _ . omit ( r , [ 'resource' ] ) )
89+ t . reviewSummation = _ . map ( _ . filter ( reviewSummations , [ 'submissionId' , t . id ] ) , r => _ . omit ( r , [ 'resource' ] ) )
90+ return t
91+ } )
7892} ) . catch ( ( err ) => {
7993 logger . logFullError ( err )
8094} )
0 commit comments