|
|
|
@ -27,9 +27,6 @@ export default class NcUpgrader {
|
|
|
|
|
this.log(`upgrade :`); |
|
|
|
|
let oldVersion; |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
ctx.ncMeta = await ctx.ncMeta.startTransaction(); |
|
|
|
|
|
|
|
|
|
const NC_VERSIONS: any[] = [ |
|
|
|
|
{ name: '0009000', handler: null }, |
|
|
|
|
{ name: '0009044', handler: null }, |
|
|
|
@ -57,17 +54,27 @@ export default class NcUpgrader {
|
|
|
|
|
oldVersion = configObj.version; |
|
|
|
|
for (const version of NC_VERSIONS) { |
|
|
|
|
// compare current version and old version
|
|
|
|
|
if (version.name > configObj.version) { |
|
|
|
|
if (version.name <= configObj.version) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let upgrderCtx: NcUpgraderCtx; |
|
|
|
|
try { |
|
|
|
|
upgrderCtx = { |
|
|
|
|
...ctx, |
|
|
|
|
ncMeta: await ctx.ncMeta.startTransaction(), |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
this.log( |
|
|
|
|
`upgrade : Upgrading '%s' => '%s'`, |
|
|
|
|
configObj.version, |
|
|
|
|
version.name |
|
|
|
|
); |
|
|
|
|
await version?.handler?.(ctx); |
|
|
|
|
await version?.handler?.(upgrderCtx); |
|
|
|
|
|
|
|
|
|
// update version in meta after each upgrade
|
|
|
|
|
config.version = version.name; |
|
|
|
|
await ctx.ncMeta.metaUpdate( |
|
|
|
|
await upgrderCtx.ncMeta.metaUpdate( |
|
|
|
|
'', |
|
|
|
|
'', |
|
|
|
|
'nc_store', |
|
|
|
@ -79,8 +86,28 @@ export default class NcUpgrader {
|
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
// todo: backup data
|
|
|
|
|
await upgrderCtx.ncMeta.commit(); |
|
|
|
|
Tele.emit('evt', { |
|
|
|
|
evt_type: 'appMigration:upgraded', |
|
|
|
|
from: oldVersion, |
|
|
|
|
to: process.env.NC_VERSION, |
|
|
|
|
}); |
|
|
|
|
} catch (e) { |
|
|
|
|
await upgrderCtx.ncMeta.rollback(e); |
|
|
|
|
Tele.emit('evt', { |
|
|
|
|
evt_type: 'appMigration:failed', |
|
|
|
|
from: oldVersion, |
|
|
|
|
to: process.env.NC_VERSION, |
|
|
|
|
msg: e.message, |
|
|
|
|
err: e?.stack?.split?.('\n').slice(0, 2).join('\n'), |
|
|
|
|
}); |
|
|
|
|
console.log( |
|
|
|
|
getUpgradeErrorLog(e, oldVersion, process.env.NC_VERSION) |
|
|
|
|
); |
|
|
|
|
throw e; |
|
|
|
|
} |
|
|
|
|
// todo: backup data
|
|
|
|
|
|
|
|
|
|
if (version.name === process.env.NC_VERSION) { |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
@ -100,24 +127,6 @@ export default class NcUpgrader {
|
|
|
|
|
await this.upgrade(ctx); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
await ctx.ncMeta.commit(); |
|
|
|
|
Tele.emit('evt', { |
|
|
|
|
evt_type: 'appMigration:upgraded', |
|
|
|
|
from: oldVersion, |
|
|
|
|
to: process.env.NC_VERSION, |
|
|
|
|
}); |
|
|
|
|
} catch (e) { |
|
|
|
|
await ctx.ncMeta.rollback(e); |
|
|
|
|
Tele.emit('evt', { |
|
|
|
|
evt_type: 'appMigration:failed', |
|
|
|
|
from: oldVersion, |
|
|
|
|
to: process.env.NC_VERSION, |
|
|
|
|
msg: e.message, |
|
|
|
|
err: e?.stack?.split?.('\n').slice(0, 2).join('\n'), |
|
|
|
|
}); |
|
|
|
|
console.log(getUpgradeErrorLog(e, oldVersion, process.env.NC_VERSION)); |
|
|
|
|
throw e; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static log(str, ...args): void { |
|
|
|
|