mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 16:06:01 +00:00
fixed loading constraints #734
This commit is contained in:
@@ -1,11 +0,0 @@
|
||||
module.exports = `
|
||||
select
|
||||
fk.constraint_name as "constraint_name",
|
||||
fk.constraint_schema as "constraint_schema",
|
||||
fk.update_rule as "update_action",
|
||||
fk.delete_rule as "delete_action",
|
||||
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
|
||||
`;
|
||||
@@ -1,9 +0,0 @@
|
||||
module.exports = `
|
||||
select
|
||||
base.table_name as "table_name",
|
||||
base.table_schema as "table_schema",
|
||||
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 and base.table_schema =SCHEMA_NAME_CONDITION
|
||||
`;
|
||||
@@ -0,0 +1,20 @@
|
||||
module.exports = `
|
||||
SELECT
|
||||
nsp.nspname AS table_schema,
|
||||
rel.relname AS table_name,
|
||||
con.conname AS constraint_name,
|
||||
nsp2.nspname AS ref_table_schema,
|
||||
rel2.relname AS ref_table_name,
|
||||
conpk.conname AS unique_constraint_name
|
||||
FROM pg_constraint con
|
||||
JOIN pg_class rel ON rel.oid = con.conrelid
|
||||
JOIN pg_namespace nsp ON nsp.oid = rel.relnamespace
|
||||
JOIN pg_class rel2 ON rel2.oid = con.confrelid
|
||||
JOIN pg_namespace nsp2 ON nsp2.oid = rel2.relnamespace
|
||||
JOIN pg_constraint conpk
|
||||
ON conpk.conrelid = con.confrelid
|
||||
AND conpk.conkey = con.confkey
|
||||
AND conpk.contype IN ('p','u') -- 'p' = primary key, 'u' = unique constraint
|
||||
WHERE con.contype = 'f' AND ('tables:' || nsp.nspname || '.' || rel.relname) =OBJECT_ID_CONDITION AND nsp.nspname =SCHEMA_NAME_CONDITION
|
||||
;
|
||||
`;
|
||||
@@ -15,10 +15,8 @@ const uniqueNames = require('./uniqueNames');
|
||||
const geometryColumns = require('./geometryColumns');
|
||||
const geographyColumns = require('./geographyColumns');
|
||||
const proceduresParameters = require('./proceduresParameters');
|
||||
|
||||
const foreignKeys = require('./foreignKeys');
|
||||
const fk_keyColumnUsage = require('./fk_key_column_usage');
|
||||
const fk_referentialConstraints = require('./fk_referential_constraints');
|
||||
const fk_tableConstraints = require('./fk_table_constraints');
|
||||
|
||||
module.exports = {
|
||||
columns,
|
||||
@@ -27,8 +25,7 @@ module.exports = {
|
||||
viewModifications,
|
||||
primaryKeys,
|
||||
fk_keyColumnUsage,
|
||||
fk_referentialConstraints,
|
||||
fk_tableConstraints,
|
||||
foreignKeys,
|
||||
views,
|
||||
routines,
|
||||
routineModifications,
|
||||
|
||||
@@ -7,6 +7,7 @@ select
|
||||
key_column_usage.column_name as "column_name"
|
||||
from information_schema.table_constraints
|
||||
inner join information_schema.key_column_usage on table_constraints.table_name = key_column_usage.table_name and table_constraints.constraint_name = key_column_usage.constraint_name
|
||||
and table_constraints.table_schema = key_column_usage.table_schema
|
||||
where
|
||||
table_constraints.table_schema !~ '^_timescaledb_'
|
||||
and table_constraints.constraint_type = 'PRIMARY KEY'
|
||||
|
||||
Reference in New Issue
Block a user