Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ function findFunctions (pgFunctions, schemaName, tableName) {

function findConstraints (pgFkConstraints, schemaName, tableName) {
return pgFkConstraints
.filter(fk => fk.source_table === `${schemaName}.${tableName}`)
.filter(fk => (fk.source_schema === schemaName && fk.source_table === tableName))
.reduce((fkConstraints, constraint) => {
const fkName = constraint.constraint_name
if (!Object.prototype.hasOwnProperty.call(fkConstraints, fkName)) {
fkConstraints[fkName] = {
targetTable: constraint.target_table,
targetTable: `${constraint.source_schema}.${constraint.target_table}`,
sourceColumns: [constraint.source_column],
targetColumns: [constraint.target_column],
updateAction: FK_ACTION_CODES[constraint.update_action],
Expand Down
5 changes: 3 additions & 2 deletions lib/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ module.exports = function queries () {
'WHERE ns.nspname = ANY($1)',

// List of foreign key constraints
'SELECT constraint_name,split_part(source_table, \'.\', 1) AS source_schema, source_table, source_column, target_table, target_column, update_action, delete_action, match_type FROM ' +
'SELECT constraint_name,(CASE position(\'.\' in SOURCE_TABLE) WHEN 0 THEN \'public\' ELSE split_part(SOURCE_TABLE, \'.\', 1) END) AS source_schema,' +
'source_table, source_column, target_table, target_column, update_action, delete_action, match_type FROM ' +
'(SELECT constraint_name,source_table::regclass::text AS source_table, source_attr.attname AS source_column, ' +
'target_table::regclass::text, target_attr.attname AS target_column, update_action, delete_action, match_type ' +
'FROM pg_attribute target_attr, pg_attribute source_attr, ' +
Expand All @@ -67,7 +68,7 @@ module.exports = function queries () {
') query2 ' +
'WHERE target_attr.attnum = target_constraints AND target_attr.attrelid = target_table ' +
'AND source_attr.attnum = source_constraints AND source_attr.attrelid = source_table) AS fk_constraints ' +
'WHERE split_part(source_table, \'.\', 1) = ANY($1)',
'WHERE (CASE position(\'.\' in SOURCE_TABLE) WHEN 0 THEN \'public\' ELSE split_part(SOURCE_TABLE, \'.\', 1) END) = ANY($1)',

// List of triggers
'SELECT trigger_name, trigger_schema, event_object_schema, event_object_table, event_manipulation, action_condition, action_statement, action_orientation, action_timing ' +
Expand Down