Skip to content

Update Migrate jobcandidates scripts III #451

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ module.exports = {
SURVEY_COLLECTOR_PREFIX: process.env.WEEKLY_SURVEY_SURVEY_COLLECTOR_PREFIX || 'Week ending',
SURVEY_MASTER_COLLECTOR_ID: process.env.WEEKLY_SURVEY_SURVEY_MASTER_COLLECTOR_ID || '',
SURVEY_MASTER_MESSAGE_ID: process.env.WEEKLY_SURVEY_SURVEY_MASTER_MESSAGE_ID || '',
SURVEY_CONTACT_GROUP_ID: process.env.WEEKLY_SURVEY_SURVEY_CONTACT_GROUP_ID || '',
SURVEY_CONTACT_GROUP_ID: process.env.WEEKLY_SURVEY_SURVEY_CONTACT_GROUP_ID || ''
},
// payment scheduler config
PAYMENT_PROCESSING: {
Expand Down
14 changes: 10 additions & 4 deletions scripts/withdrawn-migration/backup.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@ const currentStep = 'Backup'
async function backup () {
logger.info({ component: currentStep, message: '*************************** Backup process started ***************************' })
const filePath = path.join(__dirname, '/temp/')
if (fs.existsSync(filePath)) {
fs.rmdirSync(filePath, { recursive: true })
}
fs.mkdirSync(filePath)
const Op = Sequelize.Op
const jobCandidates = await JobCandidate.findAll({
where: {
status: 'placed'
}
})

let summary = 0
for (let i = 0; i < jobCandidates.length; i++) {
const jc = jobCandidates[i]
let job = null
Expand Down Expand Up @@ -56,12 +60,12 @@ async function backup () {
where: filter
})
if (candidates && candidates.length > 0) {
fs.writeFile(filePath + 'jobcandidate-backup.json', JSON.stringify(
summary += candidates.length
fs.writeFile(filePath + `jobcandidate-backup-${i+1}.json`, JSON.stringify(
candidates
), (err) => {
if (!err) {
logger.info({ component: `${currentStep} Summary`, message: `Backup up finished. There are ${candidates.length} jobCandidates that need to be updated` })
logger.info({ component: currentStep, message: '*************************** Backup process finished ***************************' })
logger.info({ component: `${currentStep} Sub`, message: `There are ${candidates.length} jobCandidates that need to be updated for userId: ${jc.userId}` })
return
}
logger.error({ component: currentStep, message: err.message })
Expand All @@ -70,6 +74,8 @@ async function backup () {
}
}
}
logger.info({ component: `${currentStep}`, message: `Report: there are ${summary} jobCandidates in total` })
logger.info({ component: currentStep, message: '*************************** Backup process finished ***************************' })
}

backup().then(() => {
Expand Down
35 changes: 22 additions & 13 deletions scripts/withdrawn-migration/migration.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,28 @@ const currentStep = 'Migration'
async function migration () {
logger.info({ component: currentStep, message: '*************************** Migration process started ***************************' })
const filePath = path.join(__dirname, '/temp/')
const data = fs.readFileSync(filePath + 'jobCandidate-backup.json', 'utf-8')
const jobCandidates = JSON.parse(data)
let summary = 0
for (var i = 0; i < jobCandidates.length; i++) {
const jc = await JobCandidate.findById(jobCandidates[i].id)
if (jc) {
const oldStatus = jc.status
const updated = await jc.update({ status: config.WITHDRAWN_STATUS_CHANGE_MAPPING[jobCandidates[i].status] })
summary++
logger.info({ component: currentStep, message: `jobCandidate with ${jc.id} status changed from ${oldStatus} to ${updated.status}` })
}
};
logger.info({ component: currentStep, message: `Totally updated ${summary} jobCandidates` })
const files = []
fs.readdirSync(filePath).forEach(async (file) => {
files.push(`${filePath}${file}`)
})
let totalSum = 0
for (let j = 0; j < files.length; j++) {
const data = fs.readFileSync(files[j], 'utf-8')
const jobCandidates = JSON.parse(data)
let summary = 0
for (let i = 0; i < jobCandidates.length; i++) {
const jc = await JobCandidate.findById(jobCandidates[i].id)
if (jc) {
const oldStatus = jc.status
const updated = await jc.update({ status: config.WITHDRAWN_STATUS_CHANGE_MAPPING[jobCandidates[i].status] })
summary++
totalSum++
logger.info({ component: currentStep, message: `jobCandidate with ${jc.id} status changed from ${oldStatus} to ${updated.status}` })
}
};
logger.info({ component: `${currentStep} Sub`, message: `Updated ${summary} jobCandidates from ${files[j]}` })
}
logger.info({ component: currentStep, message: `Report: Totally Updated ${totalSum} jobCandidates` })
logger.info({ component: currentStep, message: '*************************** Migration process finished ***************************' })
}

Expand Down
35 changes: 22 additions & 13 deletions scripts/withdrawn-migration/restore.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,28 @@ const currentStep = 'Restore'
async function restore () {
logger.info({ component: currentStep, message: '*************************** Restore process started ***************************' })
const filePath = path.join(__dirname, '/temp/')
const data = fs.readFileSync(filePath + 'jobCandidate-backup.json', 'utf-8')
const jobCandidates = JSON.parse(data)
let summary = 0
for (var i = 0; i < jobCandidates.length; i++) {
const jc = await JobCandidate.findById(jobCandidates[i].id)
if (jc) {
const oldStatus = jc.status
const updated = await jc.update({ status: jobCandidates[i].status })
summary++
logger.info({ component: currentStep, message: `jobCandidate with ${jc.id} status restored from ${oldStatus} to ${updated.status}` })
}
};
logger.info({ component: currentStep, message: `Totally restored ${summary} jobCandidates` })
const files = []
fs.readdirSync(filePath).forEach(async (file) => {
files.push(`${filePath}${file}`)
})
let totalSum = 0
for (let j = 0; j < files.length; j++) {
const data = fs.readFileSync(files[j], 'utf-8')
const jobCandidates = JSON.parse(data)
let summary = 0
for (var i = 0; i < jobCandidates.length; i++) {
const jc = await JobCandidate.findById(jobCandidates[i].id)
if (jc) {
const oldStatus = jc.status
const updated = await jc.update({ status: jobCandidates[i].status })
summary++
totalSum++
logger.info({ component: currentStep, message: `jobCandidate with ${jc.id} status restored from ${oldStatus} to ${updated.status}` })
}
};
logger.info({ component: `${currentStep} Sub`, message: `Restored ${summary} jobCandidates from ${files[j]}` })
}
logger.info({ component: currentStep, message: `Report: Totally restored ${totalSum} jobCandidates` })
logger.info({ component: currentStep, message: '*************************** Restore process finished ***************************' })
}

Expand Down