mirror of
https://github.com/frappe/books.git
synced 2024-11-09 23:30:56 +00:00
754a1a8e50
- dont notify user - catch uncaught promise in migration - prevent unable to acquire conn error
36 lines
1.1 KiB
TypeScript
36 lines
1.1 KiB
TypeScript
import { emitMainProcessError, 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 (error) {
|
|
if (!(error instanceof Error)) {
|
|
return false;
|
|
}
|
|
|
|
error.message = `Patch Failed: ${patch.name}\n${error.message}`;
|
|
emitMainProcessError(error, { patchName: patch.name, notifyUser: false });
|
|
return false;
|
|
}
|
|
|
|
await makeEntry(patch.name, dm);
|
|
return true;
|
|
}
|
|
|
|
async function makeEntry(patchName: string, dm: DatabaseManager) {
|
|
const defaultFieldValueMap = getDefaultMetaFieldValueMap() as FieldValueMap;
|
|
defaultFieldValueMap.name = patchName;
|
|
await dm.db!.insert('PatchRun', defaultFieldValueMap);
|
|
}
|