Skip to content

Commit e4db230

Browse files
#214 - Fix issue where db to es migration script did not migrate all the data
1 parent a7c441f commit e4db230

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

scripts/migrateFromDBToES.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ function * migrateRecords (tableName) {
2525
// Process until all the records from DB is fetched
2626
while (true) {
2727
const records = yield dbhelper.scanRecords(params)
28-
const totalRecords = records.Items.length
29-
logger.debug(`Number of ${tableName}s fetched from DB - ` + totalRecords)
30-
for (let i = 0; i < totalRecords; i++) {
28+
logger.debug(`Number of ${tableName}s currently fetched from DB - ` + records.Items.length)
29+
let i = 0
30+
for (const item of records.Items) {
3131
const record = {
3232
index: config.get('esConfig.ES_INDEX'),
3333
type: config.get('esConfig.ES_TYPE'),
34-
id: records.Items[i].id,
34+
id: item.id,
3535
body: {
36-
doc: _.extend({ resource: helper.camelize(tableName) }, records.Items[i]),
36+
doc: _.extend({ resource: helper.camelize(tableName) }, item),
3737
doc_as_upsert: true
3838
}
3939
}
@@ -45,12 +45,16 @@ function * migrateRecords (tableName) {
4545
promises = []
4646
batchCounter++
4747
}
48+
i++
4849
}
4950

5051
// Continue fetching the remaining records from Database
5152
if (typeof records.LastEvaluatedKey !== 'undefined') {
5253
params.ExclusiveStartKey = records.LastEvaluatedKey
5354
} else {
55+
if (promises.length > 0) {
56+
yield promises
57+
}
5458
break // If there are no more records to process, exit the loop
5559
}
5660
}

0 commit comments

Comments
 (0)