Merge branch 'master' into feature/1137-mssql-column-desc

This commit is contained in:
Pavel
2025-08-07 12:53:09 +02:00
102 changed files with 1333 additions and 341 deletions

View File

@@ -37,7 +37,7 @@
"debug": "^4.3.4",
"json-stable-stringify": "^1.0.1",
"lodash": "^4.17.21",
"pinomin": "^1.0.4",
"pinomin": "^1.0.5",
"toposort": "^2.0.2",
"uuid": "^3.4.0"
}

View File

@@ -5,7 +5,7 @@ import _pick from 'lodash/pick';
import _compact from 'lodash/compact';
import { getLogger } from './getLogger';
import { type Logger } from 'pinomin';
import { dbNameLogCategory, isCompositeDbName, splitCompositeDbName } from './schemaInfoTools';
import { isCompositeDbName, splitCompositeDbName } from './schemaInfoTools';
import { extractErrorLogData } from './stringTools';
const logger = getLogger('dbAnalyser');
@@ -77,10 +77,12 @@ export class DatabaseAnalyser<TClient = any> {
return db;
}
getLogDbInfo() {
return this.driver.getLogDbInfo(this.dbhan);
}
async fullAnalysis() {
logger.debug(
`Performing full analysis, DB=${dbNameLogCategory(this.dbhan.database)}, engine=${this.driver.engine}`
);
logger.debug(this.getLogDbInfo(), 'DBGM-00126 Performing full analysis');
const res = this.addEngineField(await this._runAnalysis());
// console.log('FULL ANALYSIS', res);
return res;
@@ -101,9 +103,7 @@ export class DatabaseAnalyser<TClient = any> {
}
async incrementalAnalysis(structure) {
logger.info(
`Performing incremental analysis, DB=${dbNameLogCategory(this.dbhan.database)}, engine=${this.driver.engine}`
);
logger.info(this.getLogDbInfo(), 'DBGM-00127 Performing incremental analysis');
this.structure = structure;
const modifications = await this.getModifications();
@@ -129,7 +129,7 @@ export class DatabaseAnalyser<TClient = any> {
this.modifications = structureModifications;
if (structureWithRowCounts) this.structure = structureWithRowCounts;
logger.info({ modifications: this.modifications }, 'DB modifications detected:');
logger.info({ ...this.getLogDbInfo(), modifications: this.modifications }, 'DBGM-00128 DB modifications detected');
return this.addEngineField(this.mergeAnalyseResult(await this._runAnalysis()));
}
@@ -274,7 +274,7 @@ export class DatabaseAnalyser<TClient = any> {
this.dbhan.feedback(obj);
}
if (obj && obj.analysingMessage) {
logger.debug(obj.analysingMessage);
logger.debug(this.getLogDbInfo(), obj.analysingMessage);
}
}
@@ -347,10 +347,16 @@ export class DatabaseAnalyser<TClient = any> {
}
try {
const res = await this.driver.query(this.dbhan, sql);
this.logger.debug({ rows: res.rows.length, template }, `Loaded analyser query`);
this.logger.debug(
{ ...this.getLogDbInfo(), rows: res.rows.length, template },
`DBGM-00129 Loaded analyser query`
);
return res;
} catch (err) {
logger.error(extractErrorLogData(err, { template }), 'Error running analyser query');
logger.error(
extractErrorLogData(err, { template, ...this.getLogDbInfo() }),
'DBGM-00130 Error running analyser query'
);
return {
rows: [],
isError: true,

View File

@@ -93,7 +93,7 @@ export class SqlGenerator {
}
private handleException = error => {
logger.error(extractErrorLogData(error), 'Unhandled error');
logger.error(extractErrorLogData(error), 'DBGM-00186 Unhandled error');
this.isUnhandledException = true;
};

View File

@@ -41,20 +41,20 @@ export function createBulkInsertStreamBase(driver: EngineDriver, stream, dbhan,
writable.structure = structure;
}
if (structure && options.dropIfExists) {
logger.info(`Dropping table ${fullNameQuoted}`);
logger.info(`DBGM-00123 Dropping table ${fullNameQuoted}`);
await driver.script(dbhan, `DROP TABLE ${fullNameQuoted}`);
}
if (options.createIfNotExists && (!structure || options.dropIfExists)) {
const dmp = driver.createDumper();
const createdTableInfo = driver.adaptTableInfo(prepareTableForImport({ ...writable.structure, ...name }));
dmp.createTable(createdTableInfo);
logger.info({ sql: dmp.s }, `Creating table ${fullNameQuoted}`);
logger.info({ sql: dmp.s }, `DBGM-00124 Creating table ${fullNameQuoted}`);
await driver.script(dbhan, dmp.s);
structure = await driver.analyseSingleTable(dbhan, name);
writable.structure = structure;
}
if (!writable.structure) {
throw new Error(`Error importing table - ${fullNameQuoted} not found`);
throw new Error(`DBGM-00125 Error importing table - ${fullNameQuoted} not found`);
}
if (options.truncate) {
await driver.script(dbhan, `TRUNCATE TABLE ${fullNameQuoted}`);
@@ -71,7 +71,7 @@ export function createBulkInsertStreamBase(driver: EngineDriver, stream, dbhan,
])
);
} catch (err) {
logger.error(extractErrorLogData(err), 'Error during preparing bulk insert table, stopped');
logger.error(extractErrorLogData(err), 'DBGM-00184 Error during preparing bulk insert table, stopped');
writable.destroy(err);
}
};
@@ -129,7 +129,7 @@ export function createBulkInsertStreamBase(driver: EngineDriver, stream, dbhan,
await driver.query(dbhan, dmp.s, { discardResult: true });
}
} catch (err) {
logger.error(extractErrorLogData(err), 'Error during base bulk insert, insert stopped');
logger.error(extractErrorLogData(err), 'DBGM-00185 Error during base bulk insert, insert stopped');
writable.destroy(err);
}
};

View File

@@ -101,7 +101,7 @@ export const driverBase = {
for (const sqlItem of splitQuery(sql, this.getQuerySplitterOptions('script'))) {
try {
if (options?.logScriptItems) {
logger.info({ sql: getLimitedQuery(sqlItem as string) }, 'Execute script item');
logger.info({ sql: getLimitedQuery(sqlItem as string) }, 'DBGM-00131 Execute script item');
}
await this.query(pool, sqlItem, { discardResult: true, ...options?.queryOptions });
} catch (err) {
@@ -254,4 +254,12 @@ export const driverBase = {
async writeQueryFromStream(dbhan, sql) {
return null;
},
getLogDbInfo(dbhan) {
return {
database: dbhan ? dbhan.database : undefined,
engine: this.engine,
conid: dbhan ? dbhan.conid : undefined,
};
},
};

View File

@@ -37,15 +37,15 @@ export function extractSchemaNameFromComposite(name: string) {
return splitCompositeDbName(name)?.schema;
}
export function dbNameLogCategory(database: string): string {
if (isCompositeDbName(database)) {
return '~composite';
}
if (database) {
return '~simple';
}
return '~nodb';
}
// export function getDbNameLogFace(database: string): string {
// if (isCompositeDbName(database)) {
// return '~composite';
// }
// if (database) {
// return '~simple';
// }
// return '~nodb';
// }
export function compositeDbNameIfNeeded(
connnection: { useSeparateSchemas: boolean },