mirror of
https://github.com/frappe/books.git
synced 2024-11-10 07:40:55 +00:00
bc39fa4feb
- Run ad-hoc patch code - Run patches based on patchOrder - Skip already run patches
41 lines
944 B
JavaScript
41 lines
944 B
JavaScript
const frappe = require('frappejs');
|
|
|
|
module.exports = async function migrate(allPatches, patchOrder) {
|
|
let executedPatchRuns = [];
|
|
try {
|
|
executedPatchRuns = (
|
|
await frappe.db.getAll({ doctype: 'PatchRun', fields: ['name'] })
|
|
).map(d => d.name);
|
|
} catch (error) {}
|
|
|
|
let patchRunOrder = patchOrder
|
|
.map(text => {
|
|
let [patch] = text.split(' ');
|
|
if (text && patch) {
|
|
return {
|
|
fileName: text,
|
|
method: allPatches[patch]
|
|
};
|
|
}
|
|
})
|
|
.filter(Boolean);
|
|
|
|
for (let patch of patchRunOrder) {
|
|
if (!executedPatchRuns.includes(patch.fileName)) {
|
|
await runPatch(patch);
|
|
}
|
|
}
|
|
};
|
|
|
|
async function runPatch(patch) {
|
|
try {
|
|
await patch.method();
|
|
let patchRun = frappe.getNewDoc('PatchRun');
|
|
patchRun.name = patch.fileName;
|
|
await patchRun.insert();
|
|
} catch (error) {
|
|
console.error(error);
|
|
console.log('Could not run patch', patch);
|
|
}
|
|
}
|