mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 13:46:00 +00:00
postgre analyser supports compisite db names
This commit is contained in:
@@ -2,7 +2,8 @@ const fp = require('lodash/fp');
|
||||
const _ = require('lodash');
|
||||
const sql = require('./sql');
|
||||
|
||||
const { DatabaseAnalyser, isTypeString, isTypeNumeric } = global.DBGATE_PACKAGES['dbgate-tools'];
|
||||
const { DatabaseAnalyser, isTypeString, isTypeNumeric, isCompositeDbName, splitCompositeDbName } =
|
||||
global.DBGATE_PACKAGES['dbgate-tools'];
|
||||
|
||||
function normalizeTypeName(dataType) {
|
||||
if (dataType == 'character varying') return 'varchar';
|
||||
@@ -56,7 +57,12 @@ class Analyser extends DatabaseAnalyser {
|
||||
|
||||
createQuery(resFileName, typeFields, replacements = {}) {
|
||||
const query = super.createQuery(sql[resFileName], typeFields, replacements);
|
||||
return query;
|
||||
const dbname = this.pool._database_name;
|
||||
const schemaCondition = isCompositeDbName(dbname)
|
||||
? `= '${splitCompositeDbName(dbname).schema}' `
|
||||
: ' IS NOT NULL ';
|
||||
|
||||
return query.replace(/=SCHEMA_NAME_CONDITION/g, schemaCondition);
|
||||
}
|
||||
|
||||
async _computeSingleObjectId() {
|
||||
|
||||
@@ -89,6 +89,7 @@ const drivers = driverBases.map(driverBase => ({
|
||||
await this.query(client, 'SET SESSION CHARACTERISTICS AS TRANSACTION READ ONLY');
|
||||
}
|
||||
|
||||
client._database_name = database;
|
||||
return client;
|
||||
},
|
||||
async close(pool) {
|
||||
|
||||
@@ -20,5 +20,6 @@ where
|
||||
or
|
||||
('views:' || table_schema || '.' || table_name) =OBJECT_ID_CONDITION
|
||||
)
|
||||
and table_schema =SCHEMA_NAME_CONDITION
|
||||
order by ordinal_position
|
||||
`;
|
||||
@@ -7,5 +7,5 @@ select
|
||||
basecol.table_name,
|
||||
basecol.ordinal_position
|
||||
from information_schema.key_column_usage basecol
|
||||
where ('tables:' || basecol.table_schema || '.' || basecol.table_name) =OBJECT_ID_CONDITION
|
||||
where ('tables:' || basecol.table_schema || '.' || basecol.table_name) =OBJECT_ID_CONDITION and basecol.table_schema =SCHEMA_NAME_CONDITION
|
||||
`;
|
||||
|
||||
@@ -7,4 +7,5 @@ select
|
||||
fk.unique_constraint_name as "unique_constraint_name",
|
||||
fk.unique_constraint_schema as "unique_constraint_schema"
|
||||
from information_schema.referential_constraints fk
|
||||
where fk.constraint_schema =SCHEMA_NAME_CONDITION
|
||||
`;
|
||||
|
||||
@@ -5,5 +5,5 @@ select
|
||||
base.constraint_name as "constraint_name",
|
||||
base.constraint_schema as "constraint_schema"
|
||||
from information_schema.table_constraints base
|
||||
where ('tables:' || base.table_schema || '.' || base.table_name) =OBJECT_ID_CONDITION
|
||||
where ('tables:' || base.table_schema || '.' || base.table_name) =OBJECT_ID_CONDITION and base.table_schema =SCHEMA_NAME_CONDITION
|
||||
`;
|
||||
|
||||
@@ -4,5 +4,5 @@ select
|
||||
f_table_name as "pure_name",
|
||||
f_geography_column as "column_name"
|
||||
from public.geography_columns
|
||||
where ('tables:' || f_table_schema || '.' || f_table_name) =OBJECT_ID_CONDITION
|
||||
where ('tables:' || f_table_schema || '.' || f_table_name) =OBJECT_ID_CONDITION and f_table_schema =SCHEMA_NAME_CONDITION
|
||||
`;
|
||||
@@ -4,5 +4,5 @@ select
|
||||
f_table_name as "pure_name",
|
||||
f_geometry_column as "column_name"
|
||||
from public.geometry_columns
|
||||
where ('tables:' || f_table_schema || '.' || f_table_name) =OBJECT_ID_CONDITION
|
||||
where ('tables:' || f_table_schema || '.' || f_table_name) =OBJECT_ID_CONDITION and f_table_schema =SCHEMA_NAME_CONDITION
|
||||
`;
|
||||
@@ -19,6 +19,7 @@ module.exports = `
|
||||
and t.relnamespace = c.oid
|
||||
and c.nspname != 'pg_catalog'
|
||||
and ('tables:' || c.nspname || '.' || t.relname) =OBJECT_ID_CONDITION
|
||||
and c.nspname =SCHEMA_NAME_CONDITION
|
||||
order by
|
||||
t.relname
|
||||
`;
|
||||
|
||||
@@ -21,6 +21,7 @@ module.exports = `
|
||||
and t.relnamespace = c.oid
|
||||
and c.nspname != 'pg_catalog'
|
||||
and ('tables:' || c.nspname || '.' || t.relname) =OBJECT_ID_CONDITION
|
||||
and c.nspname =SCHEMA_NAME_CONDITION
|
||||
order by
|
||||
t.relname
|
||||
`;
|
||||
|
||||
@@ -12,6 +12,7 @@ FROM pg_catalog.pg_class
|
||||
WHERE pg_class.relkind = 'm'
|
||||
AND pg_attribute.attnum >= 1
|
||||
AND ('matviews:' || pg_namespace.nspname || '.' || pg_class.relname) =OBJECT_ID_CONDITION
|
||||
AND pg_namespace.nspname =SCHEMA_NAME_CONDITION
|
||||
|
||||
ORDER BY pg_attribute.attnum
|
||||
`;
|
||||
|
||||
@@ -4,5 +4,5 @@ select
|
||||
schemaname as "schema_name",
|
||||
md5(definition) as "hash_code"
|
||||
from
|
||||
pg_catalog.pg_matviews WHERE schemaname NOT LIKE 'pg_%'
|
||||
pg_catalog.pg_matviews WHERE schemaname NOT LIKE 'pg_%' AND schemaname =SCHEMA_NAME_CONDITION
|
||||
`;
|
||||
|
||||
@@ -7,4 +7,5 @@ select
|
||||
from
|
||||
pg_catalog.pg_matviews WHERE schemaname NOT LIKE 'pg_%'
|
||||
and ('matviews:' || schemaname || '.' || matviewname) =OBJECT_ID_CONDITION
|
||||
and schemaname =SCHEMA_NAME_CONDITION
|
||||
`;
|
||||
|
||||
@@ -14,5 +14,6 @@ where
|
||||
and table_constraints.table_schema !~ '^_timescaledb_'
|
||||
and table_constraints.constraint_type = 'PRIMARY KEY'
|
||||
and ('tables:' || table_constraints.table_schema || '.' || table_constraints.table_name) =OBJECT_ID_CONDITION
|
||||
and table_constraints.table_schema =SCHEMA_NAME_CONDITION
|
||||
order by key_column_usage.ordinal_position
|
||||
`;
|
||||
|
||||
@@ -6,5 +6,5 @@ select
|
||||
routine_type as "object_type"
|
||||
from
|
||||
information_schema.routines where routine_schema != 'information_schema' and routine_schema != 'pg_catalog' and routine_schema !~ '^_timescaledb_'
|
||||
and routine_type in ('PROCEDURE', 'FUNCTION')
|
||||
and routine_type in ('PROCEDURE', 'FUNCTION') and routine_schema =SCHEMA_NAME_CONDITION
|
||||
`;
|
||||
|
||||
@@ -9,6 +9,7 @@ select
|
||||
max(external_language) as "language"
|
||||
from
|
||||
information_schema.routines where routine_schema != 'information_schema' and routine_schema != 'pg_catalog' and routine_schema !~ '^_timescaledb_'
|
||||
and routine_schema =SCHEMA_NAME_CONDITION
|
||||
and (
|
||||
(routine_type = 'PROCEDURE' and ('procedures:' || routine_schema || '.' || routine_name) =OBJECT_ID_CONDITION)
|
||||
or
|
||||
|
||||
@@ -8,4 +8,5 @@ and infoTables.table_schema <> 'information_schema'
|
||||
and infoTables.table_schema <> 'pg_internal'
|
||||
and infoTables.table_schema !~ '^pg_toast'
|
||||
and infoTables.table_schema !~ '^_timescaledb_'
|
||||
and infoTables.table_schema =SCHEMA_NAME_CONDITION
|
||||
`;
|
||||
|
||||
@@ -26,4 +26,5 @@ and infoTables.table_schema <> 'information_schema'
|
||||
and infoTables.table_schema <> 'pg_internal'
|
||||
and infoTables.table_schema !~ '^pg_toast'
|
||||
and infoTables.table_schema !~ '^_timescaledb_'
|
||||
and infoTables.table_schema =SCHEMA_NAME_CONDITION
|
||||
`;
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
module.exports = `
|
||||
select conname as "constraint_name" from pg_constraint where contype = 'u'
|
||||
select conname as "constraint_name" from pg_constraint where contype = 'u' and connamespace = SCHEMA_ID_CONDITION
|
||||
`;
|
||||
|
||||
@@ -4,5 +4,5 @@ select
|
||||
table_schema as "schema_name",
|
||||
md5(view_definition) as "hash_code"
|
||||
from
|
||||
information_schema.views where table_schema != 'information_schema' and table_schema != 'pg_catalog' and table_schema !~ '^_timescaledb_'
|
||||
information_schema.views where table_schema != 'information_schema' and table_schema != 'pg_catalog' and table_schema !~ '^_timescaledb_' and table_schema =SCHEMA_NAME_CONDITION
|
||||
`;
|
||||
|
||||
@@ -6,6 +6,6 @@ select
|
||||
md5(view_definition) as "hash_code"
|
||||
from
|
||||
information_schema.views
|
||||
where table_schema != 'information_schema' and table_schema != 'pg_catalog' and table_schema !~ '^_timescaledb_'
|
||||
where table_schema != 'information_schema' and table_schema != 'pg_catalog' and table_schema !~ '^_timescaledb_' and table_schema =SCHEMA_NAME_CONDITION
|
||||
and ('views:' || table_schema || '.' || table_name) =OBJECT_ID_CONDITION
|
||||
`;
|
||||
|
||||
Reference in New Issue
Block a user