From 22e9ebf85a57642a34b59ba20ac95815d27468da Mon Sep 17 00:00:00 2001 From: LieutenantRoger Date: Wed, 4 Aug 2021 22:08:01 +0800 Subject: [PATCH 1/2] migration scripts update --- scripts/withdrawn-migration/backup.js | 28 +++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/scripts/withdrawn-migration/backup.js b/scripts/withdrawn-migration/backup.js index a83c99b4..60eb0262 100644 --- a/scripts/withdrawn-migration/backup.js +++ b/scripts/withdrawn-migration/backup.js @@ -22,13 +22,25 @@ async function backup () { for (let i = 0; i < jobCandidates.length; i++) { const jc = jobCandidates[i] - const job = await Job.findById(jc.jobId) - const rb = await ResourceBooking.findOne({ - where: { - userId: jc.userId, - jobId: jc.jobId - } - }) + let job = null + try { + job = await Job.findById(jc.jobId) + } catch (error) { + // ignore the error + } + if (!job) continue + let rb = null + try { + rb = await ResourceBooking.findOne({ + where: { + userId: jc.userId, + jobId: jc.jobId + } + }) + } catch (error) { + // ignore the error + } + if (!rb) continue let completed = false if (rb && rb.endDate) { completed = new Date(rb.endDate) < new Date() && new Date(rb.endDate).toDateString() !== new Date().toDateString() @@ -42,7 +54,7 @@ async function backup () { where: filter }) if (candidates && candidates.length > 0) { - fs.writeFile(filePath + `jobcandidate-backup.json`, JSON.stringify( + fs.writeFile(filePath + 'jobcandidate-backup.json', JSON.stringify( candidates ), (err) => { if (!err) { From d0ea9c83449d9dde1f2375f4e085f87963fca97f Mon Sep 17 00:00:00 2001 From: LieutenantRoger Date: Wed, 4 Aug 2021 22:13:43 +0800 Subject: [PATCH 2/2] ignore the data integrity issue --- scripts/withdrawn-migration/backup.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/withdrawn-migration/backup.js b/scripts/withdrawn-migration/backup.js index 60eb0262..c737e143 100644 --- a/scripts/withdrawn-migration/backup.js +++ b/scripts/withdrawn-migration/backup.js @@ -26,7 +26,8 @@ async function backup () { try { job = await Job.findById(jc.jobId) } catch (error) { - // ignore the error + // log the error + logger.info({ component: currentStep, message: `==> Data integrity issue: Can't find the Job with Id ${jc.jobId}` }) } if (!job) continue let rb = null @@ -38,7 +39,8 @@ async function backup () { } }) } catch (error) { - // ignore the error + // log the error + logger.info({ component: currentStep, message: `==> Data integrity issue: Can't find the ResourceBooking whose userId is ${jc.userId} and jobId is ${jc.jobId}` }) } if (!rb) continue let completed = false