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

Use algorithm while removing index with db:rollback #24199

Merged
merged 1 commit into from Sep 21, 2017

Conversation

@meinac
Copy link
Contributor

@meinac meinac commented Mar 15, 2016

More information can be found in #24190.

Closes #24190

@rails-bot
Copy link

@rails-bot rails-bot commented Mar 15, 2016

r? @arthurnn

(@rails-bot has picked a reviewer for you, use r? to override)

activerecord/lib/active_record/migration/command_recorder.rb Outdated
@@ -163,8 +163,8 @@ def invert_add_index(args)
table, columns, options = *args
options ||= {}

index_name = options[:name]
options_hash = index_name ? { name: index_name } : { column: columns }
options_hash = options.slice(:name, :algorithm)

This comment has been minimized.

@arthurnn

arthurnn Oct 27, 2016
Member

is there other options we want to keep?

This comment has been minimized.

@kamipo

kamipo Sep 21, 2017
Member

I confirmed that remove_index handles only :name and :algorithm.

activerecord/lib/active_record/migration/command_recorder.rb Outdated
@@ -163,8 +163,8 @@ def invert_add_index(args)
table, columns, options = *args
options ||= {}

index_name = options[:name]
options_hash = index_name ? { name: index_name } : { column: columns }
options_hash = options.slice(:name, :algorithm)

This comment has been minimized.

@kamipo

kamipo Sep 21, 2017
Member

I confirmed that remove_index handles only :name and :algorithm.

activerecord/lib/active_record/migration/command_recorder.rb Outdated
index_name = options[:name]
options_hash = index_name ? { name: index_name } : { column: columns }
options_hash = options.slice(:name, :algorithm)
options_hash.merge!(column: columns) if !options_hash[:name]

This comment has been minimized.

@kamipo

kamipo Sep 21, 2017
Member

.merge!(column: columns) creates extra new column: columns hash.
How about options_hash[:column] = columns unless options_hash[:name] or simply one line fix as following?

--- a/activerecord/lib/active_record/migration/command_recorder.rb
+++ b/activerecord/lib/active_record/migration/command_recorder.rb
@@ -163,6 +163,7 @@ def invert_add_index(args)
 
           index_name = options[:name]
           options_hash = index_name ? { name: index_name } : { column: columns }
+          options_hash[:algorithm] = options[:algorithm] if options[:algorithm]
 
           [:remove_index, [table, options_hash]]
         end

This comment has been minimized.

@meinac

meinac Sep 21, 2017
Author Contributor

Thanks for your comment, I agree using merge! was not the best way.
Updated the pr.

Closes #24190
@meinac meinac force-pushed the meinac:fix_invert_add_index branch to 611f2b2 Sep 21, 2017
@kamipo kamipo merged commit 30ae39e into rails:master Sep 21, 2017
1 of 2 checks passed
1 of 2 checks passed
continuous-integration/travis-ci/pr The Travis CI build failed
Details
codeclimate All good!
Details
@meinac meinac deleted the meinac:fix_invert_add_index branch Sep 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants
You can’t perform that action at this time.