2
0
mirror of https://github.com/frappe/books.git synced 2024-12-24 11:55:46 +00:00
books/backend/database/runPatch.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

32 lines
966 B
TypeScript
Raw Normal View History

2022-03-31 07:18:32 +00:00
import { getDefaultMetaFieldValueMap } from '../helpers';
import { DatabaseManager } from './manager';
import { FieldValueMap, Patch } from './types';
export async function runPatches(patches: Patch[], dm: DatabaseManager) {
const list: { name: string; success: boolean }[] = [];
for (const patch of patches) {
const success = await runPatch(patch, dm);
list.push({ name: patch.name, success });
}
return list;
}
async function runPatch(patch: Patch, dm: DatabaseManager): Promise<boolean> {
try {
await patch.patch.execute(dm);
} catch (err) {
console.error('PATCH FAILED: ', patch.name);
console.error(err);
return false;
}
await makeEntry(patch.name, dm);
return true;
}
async function makeEntry(patchName: string, dm: DatabaseManager) {
const defaultFieldValueMap = getDefaultMetaFieldValueMap() as FieldValueMap;
defaultFieldValueMap.name = patchName;
2022-03-25 10:12:39 +00:00
await dm.db!.insert('PatchRun', defaultFieldValueMap);
}