mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 00:56:02 +00:00
SYNC: better DB analysis logging
This commit is contained in:
committed by
Diflow
parent
9886c58681
commit
53eedd2701
@@ -89,9 +89,15 @@ export class DatabaseAnalyser<TClient = any> {
|
|||||||
|
|
||||||
async fullAnalysis() {
|
async fullAnalysis() {
|
||||||
logger.debug(this.getLogDbInfo(), 'DBGM-00126 Performing full analysis');
|
logger.debug(this.getLogDbInfo(), 'DBGM-00126 Performing full analysis');
|
||||||
const res = this.addEngineField(await this._runAnalysis());
|
try {
|
||||||
|
const res = this.addEngineField(await this._runAnalysis());
|
||||||
|
logger.debug(this.getLogDbInfo(), 'DBGM-00271 Full analysis finished successfully');
|
||||||
|
return res;
|
||||||
|
} catch (err) {
|
||||||
|
logger.error(extractErrorLogData(err, this.getLogDbInfo()), 'DBGM-00272 Error during full analysis');
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
// console.log('FULL ANALYSIS', res);
|
// console.log('FULL ANALYSIS', res);
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async singleObjectAnalysis(name, typeField) {
|
async singleObjectAnalysis(name, typeField) {
|
||||||
@@ -112,32 +118,40 @@ export class DatabaseAnalyser<TClient = any> {
|
|||||||
logger.info(this.getLogDbInfo(), 'DBGM-00127 Performing incremental analysis');
|
logger.info(this.getLogDbInfo(), 'DBGM-00127 Performing incremental analysis');
|
||||||
this.structure = structure;
|
this.structure = structure;
|
||||||
|
|
||||||
const modifications = await this.getModifications();
|
try {
|
||||||
if (modifications == null) {
|
const modifications = await this.getModifications();
|
||||||
// modifications not implemented, perform full analysis
|
if (modifications == null) {
|
||||||
this.structure = null;
|
// modifications not implemented, perform full analysis
|
||||||
return this.addEngineField(await this._runAnalysis());
|
this.structure = null;
|
||||||
}
|
return this.addEngineField(await this._runAnalysis());
|
||||||
const structureModifications = modifications.filter(x => x.action != 'setTableRowCounts');
|
|
||||||
const setTableRowCounts = modifications.find(x => x.action == 'setTableRowCounts');
|
|
||||||
|
|
||||||
let structureWithRowCounts = null;
|
|
||||||
if (setTableRowCounts) {
|
|
||||||
const newStructure = mergeTableRowCounts(structure, setTableRowCounts.rowCounts);
|
|
||||||
if (areDifferentRowCounts(structure, newStructure)) {
|
|
||||||
structureWithRowCounts = newStructure;
|
|
||||||
}
|
}
|
||||||
}
|
const structureModifications = modifications.filter(x => x.action != 'setTableRowCounts');
|
||||||
|
const setTableRowCounts = modifications.find(x => x.action == 'setTableRowCounts');
|
||||||
|
|
||||||
if (structureModifications.length == 0) {
|
let structureWithRowCounts = null;
|
||||||
logger.debug(this.getLogDbInfo(), 'DBGM-00267 No changes in database structure detected');
|
if (setTableRowCounts) {
|
||||||
return structureWithRowCounts ? this.addEngineField(structureWithRowCounts) : null;
|
const newStructure = mergeTableRowCounts(structure, setTableRowCounts.rowCounts);
|
||||||
}
|
if (areDifferentRowCounts(structure, newStructure)) {
|
||||||
|
structureWithRowCounts = newStructure;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.modifications = structureModifications;
|
if (structureModifications.length == 0) {
|
||||||
if (structureWithRowCounts) this.structure = structureWithRowCounts;
|
logger.debug(this.getLogDbInfo(), 'DBGM-00267 No changes in database structure detected');
|
||||||
logger.info({ ...this.getLogDbInfo(), modifications: this.modifications }, 'DBGM-00128 DB modifications detected');
|
return structureWithRowCounts ? this.addEngineField(structureWithRowCounts) : null;
|
||||||
return this.addEngineField(this.mergeAnalyseResult(await this._runAnalysis()));
|
}
|
||||||
|
|
||||||
|
this.modifications = structureModifications;
|
||||||
|
if (structureWithRowCounts) this.structure = structureWithRowCounts;
|
||||||
|
logger.info(
|
||||||
|
{ ...this.getLogDbInfo(), modifications: this.modifications },
|
||||||
|
'DBGM-00128 DB modifications detected'
|
||||||
|
);
|
||||||
|
return this.addEngineField(this.mergeAnalyseResult(await this._runAnalysis()));
|
||||||
|
} catch (err) {
|
||||||
|
logger.error(extractErrorLogData(err, this.getLogDbInfo()), 'DBGM-00273 Error during incremental analysis');
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mergeAnalyseResult(newlyAnalysed) {
|
mergeAnalyseResult(newlyAnalysed) {
|
||||||
|
|||||||
Reference in New Issue
Block a user