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

`rename_table` should rename primary key index name #29248

Merged
merged 1 commit into from May 29, 2017

Conversation

Projects
None yet
5 participants
@yawboakye
Contributor

yawboakye commented May 27, 2017

Formerly, rename_table only renamed primary key index name if the
column's data type was sequential (serial, etc in PostgreSQL). The
problem with that is tables whose primary keys had other data types
(e.g. UUID) maintained the old primary key name. So for example,
if the cats table has a UUID primary key, and the table is renamed to
felines, the primary key index will still be called cats_pkey
instead of felines_pkey. This PR corrects it.

@rails-bot

This comment has been minimized.

rails-bot commented May 27, 2017

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @rafaelfranca (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

This repository is being automatically checked for code quality issues using Code Climate. You can see results for this analysis in the PR status below. Newly introduced issues should be fixed before a Pull Request is considered ready to review.

Please see the contribution instructions for more information.

@yawboakye

This comment has been minimized.

Contributor

yawboakye commented May 27, 2017

@rafaelfranca Looking forward to your review. Also @matthewd if you have some time 😄

@yawboakye yawboakye changed the title from `rename_table` renames primary key index name to `rename_table` should rename primary key index name May 27, 2017

@yawboakye yawboakye force-pushed the yawboakye:rename-should-rename-table-pkey branch May 28, 2017

activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb Outdated
@@ -367,6 +367,17 @@ def primary_keys(table_name) # :nodoc:
SQL
end
def primary_key_name(table_name) # :nodoc:

This comment has been minimized.

@guilleiguaran

guilleiguaran May 29, 2017

Member

I'm not sure about adding this new method to connection just for testing purposes, can we execute this query in the test instead?

This comment has been minimized.

@yawboakye

yawboakye May 29, 2017

Contributor

👍

@guilleiguaran

This comment has been minimized.

Member

guilleiguaran commented May 29, 2017

I re-ran failing job and this is green now.

I just leave a small comment, otherwise this looks very great 👍

`rename_table` renames primary key index name
Formerly, `rename_table` only renamed primary key index name if the
column's data type was sequential (serial, etc in PostgreSQL). The
problem with that is tables whose primary keys had other data types
(e.g. UUID) maintained the old primary key name. So for example,
if the `cats` table has a UUID primary key, and the table is renamed to
`felines`, the primary key index will still be called `cats_pkey`
instead of `felines_pkey`. This PR corrects it.

@yawboakye yawboakye force-pushed the yawboakye:rename-should-rename-table-pkey branch to de387ea May 29, 2017

@yawboakye

This comment has been minimized.

Contributor

yawboakye commented May 29, 2017

@guilleiguaran I made the changes you suggested

@guilleiguaran guilleiguaran merged commit e7a33a5 into rails:master May 29, 2017

2 checks passed

codeclimate no new or fixed issues
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@yawboakye yawboakye deleted the yawboakye:rename-should-rename-table-pkey branch May 30, 2017

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