Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PostgreSQL creating multiple reference foriegn key to each schema is incorrect #1956

Closed
jeebendu opened this issue May 17, 2024 · 2 comments
Closed

Comments

@jeebendu
Copy link

jeebendu commented May 17, 2024

Preconditions

  • HeidiSQL version:12.7
  • Database type and version: PostgreSQL 16.0
  • OS: Windows

Describe the bug

**i am using postgress table to create multiple schemas with same table definition.

if i am creating 3 schema in each specific schema 3 foreign key are creating which is incorrect.

Correct Behavior : it should create one foreign key instead of multiple ref from another schema**

Reproduceble script :
https://raw.githubusercontent.com/jeebendu/schema-based-multi-tenancy/main/src/main/resources/db/migration/postgress_fk_issue.sql

select tc.table_schema,
tc.constraint_type,
tc.constraint_name,
tc.table_name,
kcu.column_name,
ccu.table_schema AS foreign_table_schema,
ccu.table_name AS foreign_table_name,
ccu.column_name AS foreign_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.constraint_column_usage as ccu
ON ccu.constraint_name = tc.constraint_name
WHERE tc.constraint_type = 'FOREIGN KEY'
AND tc.table_schema = 'tenant1'
and tc.table_name = 'note';

image

image

Screenshots or Crash reports

image
image
image

PGAdmin showing correctly after export the table
image

@ansgarbecker
Copy link
Collaborator

Thanks for the comprehensive comparison and for the test script.

Fixed in the next build.

Issue was in the query for retrieving foreign keys, due to a missing join condition for constraint_column_usage.constraint_schema.

Please update via Help > Check for updates, and report back.

@ansgarbecker ansgarbecker added this to the v12.8 milestone May 18, 2024
@jeebendu
Copy link
Author

@ansgarbecker
Tested and working fine in night build
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants