diff --git a/packages/tools/src/DatabaseAnalyser.ts b/packages/tools/src/DatabaseAnalyser.ts index 045aad0f0..e10e23ab8 100644 --- a/packages/tools/src/DatabaseAnalyser.ts +++ b/packages/tools/src/DatabaseAnalyser.ts @@ -89,9 +89,15 @@ export class DatabaseAnalyser { async fullAnalysis() { 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); - return res; } async singleObjectAnalysis(name, typeField) { @@ -112,32 +118,40 @@ export class DatabaseAnalyser { logger.info(this.getLogDbInfo(), 'DBGM-00127 Performing incremental analysis'); this.structure = structure; - const modifications = await this.getModifications(); - if (modifications == null) { - // modifications not implemented, perform full analysis - 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; + try { + const modifications = await this.getModifications(); + if (modifications == null) { + // modifications not implemented, perform full analysis + 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'); - if (structureModifications.length == 0) { - logger.debug(this.getLogDbInfo(), 'DBGM-00267 No changes in database structure detected'); - return structureWithRowCounts ? this.addEngineField(structureWithRowCounts) : null; - } + let structureWithRowCounts = null; + if (setTableRowCounts) { + const newStructure = mergeTableRowCounts(structure, setTableRowCounts.rowCounts); + if (areDifferentRowCounts(structure, newStructure)) { + structureWithRowCounts = newStructure; + } + } - 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())); + if (structureModifications.length == 0) { + logger.debug(this.getLogDbInfo(), 'DBGM-00267 No changes in database structure detected'); + return structureWithRowCounts ? this.addEngineField(structureWithRowCounts) : null; + } + + 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) {