2022-01-20 20:57:29 +00:00
|
|
|
const frappe = require('frappe');
|
2020-01-28 11:00:23 +00:00
|
|
|
|
2021-11-30 12:09:11 +00:00
|
|
|
module.exports = async function runPatches(patchList) {
|
|
|
|
const patchesAlreadyRun = (
|
|
|
|
await frappe.db.knex('PatchRun').select('name')
|
|
|
|
).map(({ name }) => name);
|
2020-01-28 11:00:23 +00:00
|
|
|
|
2021-11-30 12:09:11 +00:00
|
|
|
for (let patch of patchList) {
|
|
|
|
if (patchesAlreadyRun.includes(patch.patchName)) {
|
|
|
|
continue;
|
2020-01-28 11:00:23 +00:00
|
|
|
}
|
2021-11-30 12:09:11 +00:00
|
|
|
|
|
|
|
await runPatch(patch);
|
2020-01-28 11:00:23 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-11-30 12:09:11 +00:00
|
|
|
async function runPatch({ patchName, patchFunction }) {
|
2020-01-28 11:00:23 +00:00
|
|
|
try {
|
2021-11-30 12:09:11 +00:00
|
|
|
await patchFunction();
|
|
|
|
const patchRun = frappe.getNewDoc('PatchRun');
|
|
|
|
patchRun.name = patchName;
|
2020-01-28 11:00:23 +00:00
|
|
|
await patchRun.insert();
|
|
|
|
} catch (error) {
|
2021-11-30 12:09:11 +00:00
|
|
|
console.error(`could not run ${patchName}`, error);
|
2020-01-28 11:00:23 +00:00
|
|
|
}
|
|
|
|
}
|