mirror of
https://github.com/frappe/books.git
synced 2024-12-25 12:10:06 +00:00
feat: PatchRun
- Run ad-hoc patch code - Run patches based on patchOrder - Skip already run patches
This commit is contained in:
parent
b00de586cf
commit
bc39fa4feb
2
index.js
2
index.js
@ -208,7 +208,7 @@ module.exports = {
|
||||
return newDoc;
|
||||
},
|
||||
|
||||
async getNewDoc(doctype) {
|
||||
getNewDoc(doctype) {
|
||||
let doc = this.newDoc({ doctype: doctype });
|
||||
doc._notInserted = true;
|
||||
doc.name = frappe.getRandomString();
|
||||
|
40
model/migrate.js
Normal file
40
model/migrate.js
Normal file
@ -0,0 +1,40 @@
|
||||
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);
|
||||
}
|
||||
}
|
10
models/doctype/PatchRun/PatchRun.js
Normal file
10
models/doctype/PatchRun/PatchRun.js
Normal file
@ -0,0 +1,10 @@
|
||||
module.exports = {
|
||||
name: 'PatchRun',
|
||||
fields: [
|
||||
{
|
||||
fieldname: 'name',
|
||||
fieldtype: 'Data',
|
||||
label: 'Name'
|
||||
}
|
||||
]
|
||||
};
|
@ -11,5 +11,6 @@ module.exports = {
|
||||
ToDo: require('./doctype/ToDo/ToDo.js'),
|
||||
User: require('./doctype/User/User.js'),
|
||||
UserRole: require('./doctype/UserRole/UserRole.js'),
|
||||
File: require('./doctype/File/File.js')
|
||||
File: require('./doctype/File/File.js'),
|
||||
PatchRun: require('./doctype/PatchRun/PatchRun.js')
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user