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

Change foreign key constraint names (#38) #39

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

TravisCardwell
Copy link
Contributor

This changes foreign key constraint names to be based on the table and columns of the foreign key, so that they are unique. This is a breaking change.

See #38 for details.

This changes foreign key constraint names to be based on the table and
columns of the foreign key, so that they are unique.  This is a breaking
change.
@madeline-os
Copy link
Contributor

We will need to think about providing a migration guide as part of this PR.

@TravisCardwell
Copy link
Contributor Author

I wrote my thoughts about migration for this issue.

As noted in the solution section for this issue, this change does not fix the issues with the GTableConstraintColumns instance. I planned on looking into that later since I simply disable automatic foreign key discovery for now, but perhaps I should look into it now because it would be nice to do all foreign key constraint name changes in a single PR. If it goes well, I will cherry-pick the commit into the pull request branch.

This changes the foreign key constraint names created by automatic
foreign key discovery to include all constraint columns instead of just
the first one, so that they are unique.  This is a breaking change.
@cgibbard
Copy link
Contributor

We should also be careful about the length of these names, since we're already running into problems where the generated names overlap due to length limitations.

@TravisCardwell
Copy link
Contributor Author

I have run into constraint name length issues in my project as well. Since foreign key column names are prefixed with the table name when using Beam naming conventions, the column names can be pretty long. The foreign key constraint name, named like in the following pseudo-code, can then easily exceed the PostgreSQL maximum constraint name length of 63 characters. When the column names are already minimal, the best recourse that I found was to try to shorten the table names.

intercalate "_" $ tableName : columnNames ++ ["fkey"]

Perhaps providing a way for users to specify a custom constraint name would be an acceptable workaround? This would allow developers to avoid the issue when renaming tables is not desirable.

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

Successfully merging this pull request may close these issues.

3 participants