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

r? @arthurnn

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

@@ -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)
Copy link
Member

@arthurnn arthurnn Oct 27, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there other options we want to keep?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

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]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@meinac meinac force-pushed the fix_invert_add_index branch from fd0d37d to 611f2b2 Compare September 21, 2017 09:07
@kamipo kamipo merged commit 30ae39e into rails:master Sep 21, 2017
@meinac meinac deleted the fix_invert_add_index branch September 21, 2017 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants