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

On table or column name change, rename contstraint names to match new name #3036

Open
tsujp opened this issue Oct 6, 2019 · 8 comments
Open
Assignees
Labels
a/api/graphql c/console Related to console e/easy can be wrapped up in a couple of days k/enhancement New feature or improve an existing feature p/medium non-urgent issues/features that are candidates for being included in one of the upcoming sprints

Comments

@tsujp
Copy link

tsujp commented Oct 6, 2019

Currently 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.

@marionschleifer marionschleifer added c/server Related to server k/enhancement New feature or improve an existing feature labels Oct 6, 2019
@rakeshkky
Copy link
Member

Hi @tsujp
The constraint names are something that the GraphQL engine entirely depends on Postgres. It is hard to update the constraint names explicitly for renamed tables and columns. You can run ALTER TABLE .. in SQL section of the console and the server auto-updates the required metadata.

If you feel it is good to have an edit option in console UI for constraint names, let us know in the comment. 🙂

@shakahl
Copy link

shakahl commented Feb 6, 2020

Hi @tsujp
The constraint names are something that the GraphQL engine entirely depends on Postgres. It is hard to update the constraint names explicitly for renamed tables and columns. You can run ALTER TABLE .. in SQL section of the console and the server auto-updates the required metadata.

If you feel it is good to have an edit option in console UI for constraint names, let us know in the comment. 🙂

An edit button would be great there!

@jjangga0214
Copy link
Contributor

@rakeshkky What if providing an option to automatic update, by users' intention and taking their own risk?

@rakeshkky
Copy link
Member

@jjangga0214
If server has an option for auto-update for constraint names, it should do it as expected. Even the Postgres, as a database, isn't updating the constraint names on table/column renames. By design, the server shouldn't do any DDL (on Postgres) unless it is a metadata change request. Providing an UI feature to change the constraint names would be much simpler and easy solution.

@marionschleifer marionschleifer added c/console Related to console and removed c/server Related to server labels Mar 3, 2020
@rikinsk rikinsk added e/quickfix can be wrapped up in few hours p/medium non-urgent issues/features that are candidates for being included in one of the upcoming sprints e/easy can be wrapped up in a couple of days and removed e/quickfix can be wrapped up in few hours labels Mar 3, 2020
@rikinsk rikinsk removed their assignment Mar 3, 2020
@jjangga0214
Copy link
Contributor

jjangga0214 commented Mar 9, 2020

@rakeshkky Thanks for the response.
I see.
However, it might be helpful in a practical point of view.
I recently renamed some tables. As there were more constraints than tables, manually renaming them was cumbersome. Even if Hasura provides UI, as long as it's manual renaming, it'd be still O(n) to users' viewpoint.

What if I have renamed so many tables? Then I would have to write a script, which will rename constraints by convention (using table name).

So this is what I meant. I felt it can be convenient if there's a single option on console (or API) to auto-update constraints when a table is renamed.

Of course, this does not mean Hasura should guarantee the result. I (user) have to make sure names of my constraints follow the convention, and Hasura will only handle them.

I personally don't think this is in high priority, but I believe it's useful.

How do you think?

@TheColorRed
Copy link

I came into an issue where I renamed a table to better fit the data that is in the table. Then I later realized that I wanted to restructure the data so I added another table (with the name of the table before it was renamed). I then tried adding a primary key on the table but it was saying the key already existed.

So, I was not able to add a key to this table. I then figured out that the key was already in use in the renamed table so I deleted the key and re-added it so it would reflect the table. I was then able to add the key to the newly created table.

Steps I took:

  • Initial creation: items
  • Rename: items -> user_items
  • Re-create: items
  • Add new primary key to items -- Throws error

@nbouvrette
Copy link

+1 on this feature request, it would also be nice to add a way to rename triggers for columns like updated_at

@Varun-Choudhary
Copy link
Contributor

I came into an issue where I renamed a table to better fit the data that is in the table. Then I later realized that I wanted to restructure the data so I added another table (with the name of the table before it was renamed). I then tried adding a primary key on the table but it was saying the key already existed.

So, I was not able to add a key to this table. I then figured out that the key was already in use in the renamed table so I deleted the key and re-added it so it would reflect the table. I was then able to add the key to the newly created table.

Steps I took:

  • Initial creation: items
  • Rename: items -> user_items
  • Re-create: items
  • Add new primary key to items -- Throws error

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 is items_pkey
Rename items -> user_items
Re-create: items
Add a new primary key to items -- this will add a primary with constraint name items_pkey1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a/api/graphql c/console Related to console e/easy can be wrapped up in a couple of days k/enhancement New feature or improve an existing feature p/medium non-urgent issues/features that are candidates for being included in one of the upcoming sprints
Projects
None yet
Development

No branches or pull requests