Browse Source

fix: extract correct model id on audit export and ignore table audit if missing meta (#1732)

re #1722

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/1733/head 0.90.2
Pranav C 3 years ago committed by GitHub
parent
commit
b0073e3d7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 29
      packages/nocodb/src/lib/noco/upgrader/NcUpgrader.ts
  2. 16
      packages/nocodb/src/lib/noco/upgrader/jobs/ncProjectUpgraderV2_0090000.ts

29
packages/nocodb/src/lib/noco/upgrader/NcUpgrader.ts

@ -8,6 +8,8 @@ import ncProjectUpgraderV2_0090000 from './jobs/ncProjectUpgraderV2_0090000';
const log = debug('nc:upgrader');
import { Tele } from 'nc-help';
import boxen from 'boxen';
export interface NcUpgraderCtx {
ncMeta: NcMetaIO;
}
@ -100,19 +102,40 @@ export default class NcUpgrader {
});
} catch (e) {
await ctx.ncMeta.rollback(e);
console.log('Error', e);
Tele.emit('evt', {
evt_type: 'appMigration:failed',
from: oldVersion,
to: process.env.NC_VERSION,
msg: e.message
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 {
log(`${str}`, ...args);
}
}
function getUpgradeErrorLog(e: Error, oldVersion: string, newVersion: string) {
const errorTitle = `Migration from ${oldVersion} to ${newVersion} failed`;
return boxen(
`Error
-----
${e.stack}
Please raise an issue in our github by using following link :
https://github.com/nocodb/nocodb/issues/new?labels=Type%3A%20Bug&template=bug_report.md
private;
Or contact us in our Discord community by following link :
https://discord.gg/5RgZmkW ( message @o1lab, @pranavxc or @wingkwong )`,
{ title: errorTitle, padding: 1, borderColor: 'yellow' }
);
}

16
packages/nocodb/src/lib/noco/upgrader/jobs/ncProjectUpgraderV2_0090000.ts

@ -1282,11 +1282,21 @@ async function migrateAutitLog(
};
if (audit.model_name) {
insertObj.fk_model_id = (
const model =
ctx.objModelAliasRef?.[audit.project_id]?.[audit.model_name] ||
ctx.objModelRef?.[audit.project_id]?.[audit.model_name] ||
ctx.metas?.find(m => m.id == audit.model_id)
)?.id;
// extract model by using model_id property from audit
ctx.objModelRef?.[audit.project_id]?.[
ctx.metas?.find(m => m.id == audit.model_id)?.title
] ||
ctx.objModelAliasRef?.[audit.project_id]?.[
ctx.metas?.find(m => m.id == audit.model_id)?.alias
];
// if model is not found skip audit insertion
if (!model) continue;
insertObj.fk_model_id = model.id;
}
await Audit.insert(insertObj, ncMeta);

Loading…
Cancel
Save