beam-automigrate icon indicating copy to clipboard operation
beam-automigrate copied to clipboard

Change foreign key constraint names (#38)

Open TravisCardwell opened this issue 3 years ago • 4 comments

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.

TravisCardwell avatar May 25 '22 21:05 TravisCardwell

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

madeline-os avatar May 26 '22 15:05 madeline-os

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.

TravisCardwell avatar May 27 '22 02:05 TravisCardwell

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.

cgibbard avatar Jun 13 '22 23:06 cgibbard

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.

TravisCardwell avatar Jun 14 '22 00:06 TravisCardwell