-
Notifications
You must be signed in to change notification settings - Fork 21.8k
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
Conversation
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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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] |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
fd0d37d
to
611f2b2
Compare
More information can be found in #24190.
Closes #24190