On table or column name change, rename contstraint names to match new name
See original GitHub issueCurrently Hasura does not update constraint names when changing a table or column name.
Consider having an initial table called clients
with an id
and email
column, id
is the primary-key and biginit unique autoincrementing, email
is text and unique.
Hasura will show the constraints on this table as the following:
Primary key
- id - clients_pkey
Unique keys
- email - clients_email_key
Now rename the table to users
and the constraint names will not change.
Perhaps they should be updated to keep semantic value, although it’s not breaking anything so this is probably(?) a minor priority change.
Example SQL to tie into changes:
ALTER TABLE name RENAME CONSTRAINT constraint_name TO new_constraint_name;
Also credit to elitan#8042 for suggestions relating to this issue.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:9
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Rename constraint reference that changed because of table ...
You'll have add a "new" constraint. Internally the database doesn't care about the name of things (much). Rather than using names for things ......
Read more >RENAME CONSTRAINT | CockroachDB Docs
The RENAME CONSTRAINT statement changes the name of a constraint on a column. Note: The RENAME CONSTRAINT statement performs a schema change.
Read more >Script to rename constraints and indexes to conform to a SQL ...
Problem. In many systems, keys, indexes and constraints are given names generated by the system. These system-generated names relate ...
Read more >Renaming column does not update FK definition - MySQL Bugs
The solution is to iterate over the table fields and check if any of the columns were renamed. If a column was renamed,...
Read more >Alter Table in SQL – How to Add a Column or Rename a ...
When you rename columns using ALTER TABLE you risk breaking database dependencies. If you use a database refactoring tool to change the name...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
An edit button would be great there!
Hey @TheColorRed, thanks for reporting the issue. This issue is there till
v2.12.0
but it is resolved now. Initial creation: items, let the constraint_name isitems_pkey
Rename items -> user_items Re-create: items Add a new primary key to items – this will add a primary with constraint nameitems_pkey1