mirror of
https://github.com/frappe/books.git
synced 2024-12-25 20:11:15 +00:00
27 lines
635 B
JavaScript
27 lines
635 B
JavaScript
const frappe = require('frappejs');
|
|
|
|
module.exports = async function runPatches(patchList) {
|
|
const patchesAlreadyRun = (
|
|
await frappe.db.knex('PatchRun').select('name')
|
|
).map(({ name }) => name);
|
|
|
|
for (let patch of patchList) {
|
|
if (patchesAlreadyRun.includes(patch.patchName)) {
|
|
continue;
|
|
}
|
|
|
|
await runPatch(patch);
|
|
}
|
|
};
|
|
|
|
async function runPatch({ patchName, patchFunction }) {
|
|
try {
|
|
await patchFunction();
|
|
const patchRun = frappe.getNewDoc('PatchRun');
|
|
patchRun.name = patchName;
|
|
await patchRun.insert();
|
|
} catch (error) {
|
|
console.error(`could not run ${patchName}`, error);
|
|
}
|
|
}
|