2022-03-17 11:46:49 +00:00
|
|
|
import frappe from 'frappe';
|
2020-01-28 11:00:23 +00:00
|
|
|
|
2022-03-17 11:46:49 +00:00
|
|
|
export default async function runPatches(patchList) {
|
2021-11-30 12:09:11 +00:00
|
|
|
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
|
|
|
}
|
2022-03-17 11:46:49 +00:00
|
|
|
}
|
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();
|
2022-03-22 06:00:33 +00:00
|
|
|
const patchRun = frappe.getEmptyDoc('PatchRun');
|
2021-11-30 12:09:11 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|