mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 00:56:02 +00:00
removed ttable incremental analysis for postgres
This commit is contained in:
@@ -299,23 +299,6 @@ export class DatabaseAnalyser<TClient = any> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
objectIdConditionApplied(typeFields) {
|
|
||||||
if (!this.modifications || !typeFields || this.modifications.length == 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (this.modifications.some(x => typeFields.includes(x.objectTypeField) && x.action == 'all')) {
|
|
||||||
// do not filter objects
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
const filterIds = this.modifications
|
|
||||||
.filter(x => typeFields.includes(x.objectTypeField) && (x.action == 'add' || x.action == 'change'))
|
|
||||||
.map(x => x.objectId);
|
|
||||||
if (filterIds.length == 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
async getModifications() {
|
async getModifications() {
|
||||||
const snapshot = await this._getFastSnapshot();
|
const snapshot = await this._getFastSnapshot();
|
||||||
if (!snapshot) return null;
|
if (!snapshot) return null;
|
||||||
|
|||||||
@@ -84,9 +84,7 @@ class Analyser extends DatabaseAnalyser {
|
|||||||
|
|
||||||
async _runAnalysis() {
|
async _runAnalysis() {
|
||||||
this.feedback({ analysingMessage: 'DBGM-00241 Loading tables' });
|
this.feedback({ analysingMessage: 'DBGM-00241 Loading tables' });
|
||||||
const tables = await this.analyserQuery(this.driver.dialect.stringAgg ? 'tableModifications' : 'tableList', [
|
const tables = await this.analyserQuery('tableList', ['tables']);
|
||||||
'tables',
|
|
||||||
]);
|
|
||||||
|
|
||||||
this.feedback({ analysingMessage: 'DBGM-00242 Loading columns' });
|
this.feedback({ analysingMessage: 'DBGM-00242 Loading columns' });
|
||||||
const columns = await this.analyserQuery('columns', ['tables', 'views']);
|
const columns = await this.analyserQuery('columns', ['tables', 'views']);
|
||||||
@@ -99,60 +97,55 @@ class Analyser extends DatabaseAnalyser {
|
|||||||
this.feedback({ analysingMessage: 'DBGM-00244 Loading foreign key constraints' });
|
this.feedback({ analysingMessage: 'DBGM-00244 Loading foreign key constraints' });
|
||||||
// const fk_tableConstraints = await this.analyserQuery('fk_tableConstraints', ['tables']);
|
// const fk_tableConstraints = await this.analyserQuery('fk_tableConstraints', ['tables']);
|
||||||
|
|
||||||
if (this.objectIdConditionApplied(['tables'])) {
|
this.feedback({ analysingMessage: 'DBGM-00245 Loading foreign key refs' });
|
||||||
this.feedback({ analysingMessage: 'DBGM-00000 Loading foreign key refs' });
|
const foreignKeys = await this.analyserQuery('foreignKeys', ['tables']);
|
||||||
fkColumns = await this.analyserQuery('foreignKeyColumns', ['tables']);
|
|
||||||
} else {
|
|
||||||
this.feedback({ analysingMessage: 'DBGM-00245 Loading foreign key refs' });
|
|
||||||
const foreignKeys = await this.analyserQuery('foreignKeys', ['tables']);
|
|
||||||
|
|
||||||
this.feedback({ analysingMessage: 'DBGM-00246 Loading foreign key columns' });
|
this.feedback({ analysingMessage: 'DBGM-00246 Loading foreign key columns' });
|
||||||
const fk_keyColumnUsage = await this.analyserQuery('fk_keyColumnUsage', ['tables']);
|
const fk_keyColumnUsage = await this.analyserQuery('fk_keyColumnUsage', ['tables']);
|
||||||
|
|
||||||
// const cntKey = x => `${x.constraint_name}|${x.constraint_schema}`;
|
// const cntKey = x => `${x.constraint_name}|${x.constraint_schema}`;
|
||||||
const fkRows = [];
|
const fkRows = [];
|
||||||
// const fkConstraintDct = _.keyBy(fk_tableConstraints.rows, cntKey);
|
// const fkConstraintDct = _.keyBy(fk_tableConstraints.rows, cntKey);
|
||||||
for (const fkRef of foreignKeys.rows) {
|
for (const fkRef of foreignKeys.rows) {
|
||||||
// const cntBase = fkConstraintDct[cntKey(fkRef)];
|
// const cntBase = fkConstraintDct[cntKey(fkRef)];
|
||||||
// const cntRef = fkConstraintDct[`${fkRef.unique_constraint_name}|${fkRef.unique_constraint_schema}`];
|
// const cntRef = fkConstraintDct[`${fkRef.unique_constraint_name}|${fkRef.unique_constraint_schema}`];
|
||||||
// if (!cntBase || !cntRef) continue;
|
// if (!cntBase || !cntRef) continue;
|
||||||
const baseCols = _.sortBy(
|
const baseCols = _.sortBy(
|
||||||
fk_keyColumnUsage.rows.filter(
|
fk_keyColumnUsage.rows.filter(
|
||||||
x =>
|
x =>
|
||||||
x.table_name == fkRef.table_name &&
|
x.table_name == fkRef.table_name &&
|
||||||
x.constraint_name == fkRef.constraint_name &&
|
x.constraint_name == fkRef.constraint_name &&
|
||||||
x.table_schema == fkRef.table_schema
|
x.table_schema == fkRef.table_schema
|
||||||
),
|
),
|
||||||
'ordinal_position'
|
'ordinal_position'
|
||||||
);
|
);
|
||||||
const refCols = _.sortBy(
|
const refCols = _.sortBy(
|
||||||
fk_keyColumnUsage.rows.filter(
|
fk_keyColumnUsage.rows.filter(
|
||||||
x =>
|
x =>
|
||||||
x.table_name == fkRef.ref_table_name &&
|
x.table_name == fkRef.ref_table_name &&
|
||||||
x.constraint_name == fkRef.unique_constraint_name &&
|
x.constraint_name == fkRef.unique_constraint_name &&
|
||||||
x.table_schema == fkRef.ref_table_schema
|
x.table_schema == fkRef.ref_table_schema
|
||||||
),
|
),
|
||||||
'ordinal_position'
|
'ordinal_position'
|
||||||
);
|
);
|
||||||
if (baseCols.length != refCols.length) continue;
|
if (baseCols.length != refCols.length) continue;
|
||||||
|
|
||||||
for (let i = 0; i < baseCols.length; i++) {
|
for (let i = 0; i < baseCols.length; i++) {
|
||||||
const baseCol = baseCols[i];
|
const baseCol = baseCols[i];
|
||||||
const refCol = refCols[i];
|
const refCol = refCols[i];
|
||||||
|
|
||||||
fkRows.push({
|
fkRows.push({
|
||||||
...fkRef,
|
...fkRef,
|
||||||
pure_name: fkRef.table_name,
|
pure_name: fkRef.table_name,
|
||||||
schema_name: fkRef.table_schema,
|
schema_name: fkRef.table_schema,
|
||||||
ref_table_name: fkRef.ref_table_name,
|
ref_table_name: fkRef.ref_table_name,
|
||||||
ref_schema_name: fkRef.ref_table_schema,
|
ref_schema_name: fkRef.ref_table_schema,
|
||||||
column_name: baseCol.column_name,
|
column_name: baseCol.column_name,
|
||||||
ref_column_name: refCol.column_name,
|
ref_column_name: refCol.column_name,
|
||||||
});
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
fkColumns = { rows: fkRows };
|
|
||||||
}
|
}
|
||||||
|
fkColumns = { rows: fkRows };
|
||||||
|
|
||||||
this.feedback({ analysingMessage: 'DBGM-00247 Loading views' });
|
this.feedback({ analysingMessage: 'DBGM-00247 Loading views' });
|
||||||
const views = await this.analyserQuery('views', ['views']);
|
const views = await this.analyserQuery('views', ['views']);
|
||||||
@@ -401,9 +394,6 @@ class Analyser extends DatabaseAnalyser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async _getFastSnapshot() {
|
async _getFastSnapshot() {
|
||||||
const tableModificationsQueryData = this.driver.dialect.stringAgg
|
|
||||||
? await this.analyserQuery('tableModifications')
|
|
||||||
: null;
|
|
||||||
const viewModificationsQueryData = await this.analyserQuery('viewModifications');
|
const viewModificationsQueryData = await this.analyserQuery('viewModifications');
|
||||||
const matviewModificationsQueryData = this.driver.dialect.materializedViews
|
const matviewModificationsQueryData = this.driver.dialect.materializedViews
|
||||||
? await this.analyserQuery('matviewModifications')
|
? await this.analyserQuery('matviewModifications')
|
||||||
@@ -411,15 +401,7 @@ class Analyser extends DatabaseAnalyser {
|
|||||||
const routineModificationsQueryData = await this.analyserQuery('routineModifications');
|
const routineModificationsQueryData = await this.analyserQuery('routineModifications');
|
||||||
|
|
||||||
return {
|
return {
|
||||||
tables: tableModificationsQueryData
|
tables: null,
|
||||||
? tableModificationsQueryData.rows.map(x => ({
|
|
||||||
objectId: `tables:${x.schema_name}.${x.pure_name}`,
|
|
||||||
pureName: x.pure_name,
|
|
||||||
schemaName: x.schema_name,
|
|
||||||
sizeBytes: x.size_bytes,
|
|
||||||
contentHash: `${x.hash_code_columns}-${x.hash_code_constraints}`,
|
|
||||||
}))
|
|
||||||
: null,
|
|
||||||
views: viewModificationsQueryData.rows.map(x => ({
|
views: viewModificationsQueryData.rows.map(x => ({
|
||||||
objectId: `views:${x.schema_name}.${x.pure_name}`,
|
objectId: `views:${x.schema_name}.${x.pure_name}`,
|
||||||
pureName: x.pure_name,
|
pureName: x.pure_name,
|
||||||
|
|||||||
@@ -1,36 +0,0 @@
|
|||||||
module.exports = `
|
|
||||||
SELECT
|
|
||||||
tc.table_schema as schema_name,
|
|
||||||
tc.table_name as pure_name,
|
|
||||||
tc.constraint_name,
|
|
||||||
tc_pk.table_schema AS ref_schema_name,
|
|
||||||
tc_pk.table_name AS ref_table_name,
|
|
||||||
rc.unique_constraint_name,
|
|
||||||
kcu.column_name,
|
|
||||||
kcu.ordinal_position,
|
|
||||||
ccu.column_name AS ref_column_name
|
|
||||||
FROM information_schema.table_constraints AS tc
|
|
||||||
JOIN information_schema.key_column_usage AS kcu
|
|
||||||
ON tc.constraint_name = kcu.constraint_name
|
|
||||||
AND tc.table_schema = kcu.table_schema
|
|
||||||
JOIN information_schema.referential_constraints AS rc
|
|
||||||
ON rc.constraint_name = tc.constraint_name
|
|
||||||
AND rc.constraint_schema = tc.table_schema
|
|
||||||
JOIN information_schema.table_constraints AS tc_pk
|
|
||||||
ON tc_pk.constraint_name = rc.unique_constraint_name
|
|
||||||
AND tc_pk.constraint_schema = rc.unique_constraint_schema
|
|
||||||
JOIN information_schema.key_column_usage AS ccu
|
|
||||||
ON ccu.constraint_name = rc.unique_constraint_name
|
|
||||||
AND ccu.constraint_schema = rc.unique_constraint_schema
|
|
||||||
AND ccu.ordinal_position = kcu.position_in_unique_constraint
|
|
||||||
WHERE tc.constraint_type = 'FOREIGN KEY'
|
|
||||||
AND (('tables:' || tc.table_schema || '.' || tc.table_name) =OBJECT_ID_CONDITION AND tc.table_schema =SCHEMA_NAME_CONDITION)
|
|
||||||
OR
|
|
||||||
(('tables:' || tc_pk.table_schema || '.' || tc_pk.table_name) =OBJECT_ID_CONDITION AND tc.table_schema =SCHEMA_NAME_CONDITION)
|
|
||||||
ORDER BY
|
|
||||||
tc.table_schema,
|
|
||||||
tc.table_name,
|
|
||||||
tc.constraint_name,
|
|
||||||
kcu.ordinal_position
|
|
||||||
;
|
|
||||||
`;
|
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
const columns = require('./columns');
|
const columns = require('./columns');
|
||||||
const tableModifications = require('./tableModifications');
|
|
||||||
const tableList = require('./tableList');
|
const tableList = require('./tableList');
|
||||||
const viewModifications = require('./viewModifications');
|
const viewModifications = require('./viewModifications');
|
||||||
const matviewModifications = require('./matviewModifications');
|
const matviewModifications = require('./matviewModifications');
|
||||||
@@ -16,7 +15,6 @@ const geometryColumns = require('./geometryColumns');
|
|||||||
const geographyColumns = require('./geographyColumns');
|
const geographyColumns = require('./geographyColumns');
|
||||||
const proceduresParameters = require('./proceduresParameters');
|
const proceduresParameters = require('./proceduresParameters');
|
||||||
const foreignKeys = require('./foreignKeys');
|
const foreignKeys = require('./foreignKeys');
|
||||||
const foreignKeyColumns = require('./foreignKeyColumns');
|
|
||||||
const triggers = require('./triggers');
|
const triggers = require('./triggers');
|
||||||
const listDatabases = require('./listDatabases');
|
const listDatabases = require('./listDatabases');
|
||||||
const listVariables = require('./listVariables');
|
const listVariables = require('./listVariables');
|
||||||
@@ -26,12 +24,10 @@ const fk_keyColumnUsage = require('./fk_key_column_usage');
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
columns,
|
columns,
|
||||||
tableModifications,
|
|
||||||
tableList,
|
tableList,
|
||||||
viewModifications,
|
viewModifications,
|
||||||
primaryKeys,
|
primaryKeys,
|
||||||
fk_keyColumnUsage,
|
fk_keyColumnUsage,
|
||||||
foreignKeyColumns,
|
|
||||||
foreignKeys,
|
foreignKeys,
|
||||||
views,
|
views,
|
||||||
routines,
|
routines,
|
||||||
|
|||||||
@@ -5,6 +5,6 @@ from information_schema.tables infoTables
|
|||||||
where infoTables.table_type not like '%VIEW%'
|
where infoTables.table_type not like '%VIEW%'
|
||||||
and ('tables:' || infoTables.table_schema || '.' || infoTables.table_name) =OBJECT_ID_CONDITION
|
and ('tables:' || infoTables.table_schema || '.' || infoTables.table_name) =OBJECT_ID_CONDITION
|
||||||
and infoTables.table_schema <> 'pg_internal'
|
and infoTables.table_schema <> 'pg_internal'
|
||||||
and infoTables.table_schema !~ '^_timescaledb_'
|
and infoTables.table_schema !~ '^_timescaledb_'
|
||||||
and infoTables.table_schema =SCHEMA_NAME_CONDITION
|
and infoTables.table_schema =SCHEMA_NAME_CONDITION
|
||||||
`;
|
`;
|
||||||
|
|||||||
@@ -1,28 +0,0 @@
|
|||||||
module.exports = `
|
|
||||||
select infoTables.table_schema as "schema_name", infoTables.table_name as "pure_name",
|
|
||||||
(
|
|
||||||
select $md5Function(string_agg(
|
|
||||||
infoColumns.column_name || '|' || infoColumns.data_type || '|' || infoColumns.is_nullable::varchar(255) || '|' || coalesce(infoColumns.character_maximum_length, -1)::varchar(255)
|
|
||||||
|| '|' || coalesce(infoColumns.numeric_precision, -1)::varchar(255) ,
|
|
||||||
',' order by infoColumns.ordinal_position
|
|
||||||
)) as "hash_code_columns"
|
|
||||||
from information_schema.columns infoColumns
|
|
||||||
where infoColumns.table_schema = infoTables.table_schema and infoColumns.table_name = infoTables.table_name
|
|
||||||
),
|
|
||||||
(
|
|
||||||
select $md5Function(string_agg(
|
|
||||||
infoConstraints.constraint_name || '|' || infoConstraints.constraint_type ,
|
|
||||||
',' order by infoConstraints.constraint_name
|
|
||||||
)) as "hash_code_constraints"
|
|
||||||
from information_schema.table_constraints infoConstraints
|
|
||||||
where infoConstraints.table_schema = infoTables.table_schema and infoConstraints.table_name = infoTables.table_name
|
|
||||||
),
|
|
||||||
pg_relation_size('"'||infoTables.table_schema||'"."'||infoTables.table_name||'"') as "size_bytes"
|
|
||||||
|
|
||||||
from information_schema.tables infoTables
|
|
||||||
where infoTables.table_type not like '%VIEW%'
|
|
||||||
and ('tables:' || infoTables.table_schema || '.' || infoTables.table_name) =OBJECT_ID_CONDITION
|
|
||||||
and infoTables.table_schema <> 'pg_internal'
|
|
||||||
and infoTables.table_schema !~ '^_timescaledb_'
|
|
||||||
and infoTables.table_schema =SCHEMA_NAME_CONDITION
|
|
||||||
`;
|
|
||||||
Reference in New Issue
Block a user