schema update in database analyser

This commit is contained in:
SPRINX0\prochazka
2024-09-18 15:37:34 +02:00
parent 327d43096f
commit 5ab686b721
9 changed files with 101 additions and 22 deletions

View File

@@ -79,6 +79,12 @@ class MsSqlAnalyser extends DatabaseAnalyser {
this.singleObjectId = resId.rows[0].id;
}
async readSchemaList() {
const schemaRows = await this.analyserQuery('getSchemas');
const schemas = schemaRows.rows;
return schemas;
}
async _runAnalysis() {
this.feedback({ analysingMessage: 'Loading tables' });
const tablesRows = await this.analyserQuery('tables', ['tables']);
@@ -88,8 +94,6 @@ class MsSqlAnalyser extends DatabaseAnalyser {
const pkColumnsRows = await this.analyserQuery('primaryKeys', ['tables']);
this.feedback({ analysingMessage: 'Loading foreign keys' });
const fkColumnsRows = await this.analyserQuery('foreignKeys', ['tables']);
this.feedback({ analysingMessage: 'Loading schemas' });
const schemaRows = await this.analyserQuery('getSchemas');
this.feedback({ analysingMessage: 'Loading indexes' });
const indexesRows = await this.analyserQuery('indexes', ['tables']);
this.feedback({ analysingMessage: 'Loading index columns' });
@@ -99,17 +103,10 @@ class MsSqlAnalyser extends DatabaseAnalyser {
this.feedback({ analysingMessage: 'Loading table sizes' });
const tableSizes = await this.analyserQuery('tableSizes');
const schemas = schemaRows.rows;
const tableSizesDict = _.mapValues(_.keyBy(tableSizes.rows, 'objectId'), 'tableRowCount');
this.feedback({ analysingMessage: 'Loading SQL code' });
const sqlCodeRows = await this.analyserQuery('loadSqlCode', [
'views',
'procedures',
'functions',
'triggers',
]);
const sqlCodeRows = await this.analyserQuery('loadSqlCode', ['views', 'procedures', 'functions', 'triggers']);
const getCreateSql = row =>
sqlCodeRows.rows
.filter(x => x.pureName == row.pureName && x.schemaName == row.schemaName)
@@ -182,7 +179,6 @@ class MsSqlAnalyser extends DatabaseAnalyser {
views,
procedures,
functions,
schemas,
defaultSchema: defaultSchemaRows.rows[0] ? defaultSchemaRows.rows[0].name : undefined,
};
}

View File

@@ -312,6 +312,17 @@ class Analyser extends DatabaseAnalyser {
return res;
}
async readSchemaList() {
const schemaRows = await this.analyserQuery('getSchemas');
const schemas = schemaRows.rows.map(x => ({
schemaName: x.schema_name,
objectId: `schemas:${x.schema_name}`,
}));
return schemas;
}
async _getFastSnapshot() {
const tableModificationsQueryData = this.driver.dialect.stringAgg
? await this.analyserQuery('tableModifications')

View File

@@ -0,0 +1 @@
module.exports = `select oid as "object_id", nspname as "schema_name" from pg_catalog.pg_namespace`;

View File

@@ -12,6 +12,7 @@ const matviewColumns = require('./matviewColumns');
const indexes = require('./indexes');
const indexcols = require('./indexcols');
const uniqueNames = require('./uniqueNames');
const getSchemas = require('./getSchemas');
const geometryColumns = require('./geometryColumns');
const geographyColumns = require('./geographyColumns');
@@ -39,4 +40,5 @@ module.exports = {
uniqueNames,
geometryColumns,
geographyColumns,
getSchemas,
};