mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-29 06:26:00 +00:00
postgreSQL - extended nalyser logs
This commit is contained in:
@@ -41,7 +41,7 @@ function configureLogger() {
|
|||||||
{
|
{
|
||||||
type: 'stream',
|
type: 'stream',
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
level: process.env.FILE_LOG_LEVEL || process.env.LOG_LEVEL || 'info',
|
level: process.env.FILE_LOG_LEVEL || process.env.LOG_LEVEL || 'debug',
|
||||||
stream: fs.createWriteStream(logsFilePath, { flags: 'a' }),
|
stream: fs.createWriteStream(logsFilePath, { flags: 'a' }),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import _groupBy from 'lodash/groupBy';
|
|||||||
import _pick from 'lodash/pick';
|
import _pick from 'lodash/pick';
|
||||||
import _compact from 'lodash/compact';
|
import _compact from 'lodash/compact';
|
||||||
import { getLogger } from './getLogger';
|
import { getLogger } from './getLogger';
|
||||||
|
import { type Logger } from 'pinomin';
|
||||||
|
|
||||||
const logger = getLogger('dbAnalyser');
|
const logger = getLogger('dbAnalyser');
|
||||||
|
|
||||||
@@ -37,9 +38,11 @@ export class DatabaseAnalyser {
|
|||||||
singleObjectFilter: any;
|
singleObjectFilter: any;
|
||||||
singleObjectId: string = null;
|
singleObjectId: string = null;
|
||||||
dialect: SqlDialect;
|
dialect: SqlDialect;
|
||||||
|
logger: Logger;
|
||||||
|
|
||||||
constructor(public pool, public driver: EngineDriver, version) {
|
constructor(public pool, public driver: EngineDriver, version) {
|
||||||
this.dialect = (driver?.dialectByVersion && driver?.dialectByVersion(version)) || driver?.dialect;
|
this.dialect = (driver?.dialectByVersion && driver?.dialectByVersion(version)) || driver?.dialect;
|
||||||
|
this.logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
async _runAnalysis() {
|
async _runAnalysis() {
|
||||||
|
|||||||
@@ -70,20 +70,29 @@ class Analyser extends DatabaseAnalyser {
|
|||||||
const tables = await this.analyserQuery(this.driver.dialect.stringAgg ? 'tableModifications' : 'tableList', [
|
const tables = await this.analyserQuery(this.driver.dialect.stringAgg ? 'tableModifications' : 'tableList', [
|
||||||
'tables',
|
'tables',
|
||||||
]);
|
]);
|
||||||
|
this.logger.debug({ count: tables.rows.length }, 'Tables loaded');
|
||||||
|
|
||||||
this.feedback({ analysingMessage: 'Loading columns' });
|
this.feedback({ analysingMessage: 'Loading columns' });
|
||||||
const columns = await this.analyserQuery('columns', ['tables', 'views']);
|
const columns = await this.analyserQuery('columns', ['tables', 'views']);
|
||||||
|
this.logger.debug({ count: columns.rows.length }, 'Columns loaded');
|
||||||
|
|
||||||
this.feedback({ analysingMessage: 'Loading primary keys' });
|
this.feedback({ analysingMessage: 'Loading primary keys' });
|
||||||
const pkColumns = await this.analyserQuery('primaryKeys', ['tables']);
|
const pkColumns = await this.analyserQuery('primaryKeys', ['tables']);
|
||||||
|
this.logger.debug({ count: pkColumns.rows.length }, 'Primary keys loaded');
|
||||||
|
|
||||||
let fkColumns = null;
|
let fkColumns = null;
|
||||||
|
|
||||||
this.feedback({ analysingMessage: 'Loading foreign key constraints' });
|
this.feedback({ analysingMessage: 'Loading foreign key constraints' });
|
||||||
const fk_tableConstraints = await this.analyserQuery('fk_tableConstraints', ['tables']);
|
const fk_tableConstraints = await this.analyserQuery('fk_tableConstraints', ['tables']);
|
||||||
|
this.logger.debug({ count: fk_tableConstraints.rows.length }, 'Foreign keys loaded');
|
||||||
|
|
||||||
this.feedback({ analysingMessage: 'Loading foreign key refs' });
|
this.feedback({ analysingMessage: 'Loading foreign key refs' });
|
||||||
const fk_referentialConstraints = await this.analyserQuery('fk_referentialConstraints', ['tables']);
|
const fk_referentialConstraints = await this.analyserQuery('fk_referentialConstraints', ['tables']);
|
||||||
|
this.logger.debug({ count: fk_referentialConstraints.rows.length }, 'Foreign key refs loaded');
|
||||||
|
|
||||||
this.feedback({ analysingMessage: 'Loading foreign key columns' });
|
this.feedback({ analysingMessage: 'Loading foreign key columns' });
|
||||||
const fk_keyColumnUsage = await this.analyserQuery('fk_keyColumnUsage', ['tables']);
|
const fk_keyColumnUsage = await this.analyserQuery('fk_keyColumnUsage', ['tables']);
|
||||||
|
this.logger.debug({ count: fk_keyColumnUsage.rows.length }, 'Foreign key columns loaded');
|
||||||
|
|
||||||
const cntKey = x => `${x.constraint_name}|${x.constraint_schema}`;
|
const cntKey = x => `${x.constraint_name}|${x.constraint_schema}`;
|
||||||
const fkRows = [];
|
const fkRows = [];
|
||||||
@@ -125,34 +134,50 @@ class Analyser extends DatabaseAnalyser {
|
|||||||
|
|
||||||
this.feedback({ analysingMessage: 'Loading views' });
|
this.feedback({ analysingMessage: 'Loading views' });
|
||||||
const views = await this.analyserQuery('views', ['views']);
|
const views = await this.analyserQuery('views', ['views']);
|
||||||
|
this.logger.debug({ count: views.rows.length }, 'Views loaded');
|
||||||
|
|
||||||
this.feedback({ analysingMessage: 'Loading materialized views' });
|
this.feedback({ analysingMessage: 'Loading materialized views' });
|
||||||
const matviews = this.driver.dialect.materializedViews ? await this.analyserQuery('matviews', ['matviews']) : null;
|
const matviews = this.driver.dialect.materializedViews ? await this.analyserQuery('matviews', ['matviews']) : null;
|
||||||
|
this.logger.debug({ count: matviews.rows.length }, 'Materialized views loaded');
|
||||||
|
|
||||||
this.feedback({ analysingMessage: 'Loading materialized view columns' });
|
this.feedback({ analysingMessage: 'Loading materialized view columns' });
|
||||||
const matviewColumns = this.driver.dialect.materializedViews
|
const matviewColumns = this.driver.dialect.materializedViews
|
||||||
? await this.analyserQuery('matviewColumns', ['matviews'])
|
? await this.analyserQuery('matviewColumns', ['matviews'])
|
||||||
: null;
|
: null;
|
||||||
|
this.logger.debug({ count: matviewColumns.rows.length }, 'Materialized view columns loaded');
|
||||||
|
|
||||||
this.feedback({ analysingMessage: 'Loading routines' });
|
this.feedback({ analysingMessage: 'Loading routines' });
|
||||||
const routines = await this.analyserQuery('routines', ['procedures', 'functions']);
|
const routines = await this.analyserQuery('routines', ['procedures', 'functions']);
|
||||||
|
this.logger.debug({ count: routines.rows.length }, 'Routines loaded');
|
||||||
|
|
||||||
this.feedback({ analysingMessage: 'Loading indexes' });
|
this.feedback({ analysingMessage: 'Loading indexes' });
|
||||||
const indexes = this.driver.__analyserInternals.skipIndexes
|
const indexes = this.driver.__analyserInternals.skipIndexes
|
||||||
? { rows: [] }
|
? { rows: [] }
|
||||||
: await this.analyserQuery('indexes', ['tables']);
|
: await this.analyserQuery('indexes', ['tables']);
|
||||||
|
this.logger.debug({ count: indexes.rows.length }, 'Indexes loaded');
|
||||||
|
|
||||||
this.feedback({ analysingMessage: 'Loading index columns' });
|
this.feedback({ analysingMessage: 'Loading index columns' });
|
||||||
const indexcols = this.driver.__analyserInternals.skipIndexes
|
const indexcols = this.driver.__analyserInternals.skipIndexes
|
||||||
? { rows: [] }
|
? { rows: [] }
|
||||||
: await this.analyserQuery('indexcols', ['tables']);
|
: await this.analyserQuery('indexcols', ['tables']);
|
||||||
|
this.logger.debug({ count: indexcols.rows.length }, 'Indexes columns loaded');
|
||||||
|
|
||||||
this.feedback({ analysingMessage: 'Loading unique names' });
|
this.feedback({ analysingMessage: 'Loading unique names' });
|
||||||
const uniqueNames = await this.analyserQuery('uniqueNames', ['tables']);
|
const uniqueNames = await this.analyserQuery('uniqueNames', ['tables']);
|
||||||
|
this.logger.debug({ count: uniqueNames.rows.length }, 'Uniques loaded');
|
||||||
|
|
||||||
let geometryColumns = { rows: [] };
|
let geometryColumns = { rows: [] };
|
||||||
if (views.rows.find(x => x.pure_name == 'geometry_columns' && x.schema_name == 'public')) {
|
if (views.rows.find(x => x.pure_name == 'geometry_columns' && x.schema_name == 'public')) {
|
||||||
this.feedback({ analysingMessage: 'Loading geometry columns' });
|
this.feedback({ analysingMessage: 'Loading geometry columns' });
|
||||||
geometryColumns = await this.analyserQuery('geometryColumns', ['tables']);
|
geometryColumns = await this.analyserQuery('geometryColumns', ['tables']);
|
||||||
|
this.logger.debug({ count: geometryColumns.rows.length }, 'Geometry columns loaded');
|
||||||
}
|
}
|
||||||
|
|
||||||
let geographyColumns = { rows: [] };
|
let geographyColumns = { rows: [] };
|
||||||
if (views.rows.find(x => x.pure_name == 'geography_columns' && x.schema_name == 'public')) {
|
if (views.rows.find(x => x.pure_name == 'geography_columns' && x.schema_name == 'public')) {
|
||||||
this.feedback({ analysingMessage: 'Loading geography columns' });
|
this.feedback({ analysingMessage: 'Loading geography columns' });
|
||||||
geographyColumns = await this.analyserQuery('geographyColumns', ['tables']);
|
geographyColumns = await this.analyserQuery('geographyColumns', ['tables']);
|
||||||
|
this.logger.debug({ count: geographyColumns.rows.length }, 'Geography columns loaded');
|
||||||
}
|
}
|
||||||
|
|
||||||
this.feedback({ analysingMessage: 'Finalizing DB structure' });
|
this.feedback({ analysingMessage: 'Finalizing DB structure' });
|
||||||
|
|||||||
Reference in New Issue
Block a user