aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorMarc-Andre Lafortune <github@marc-andre.ca>2012-11-19 02:12:40 -0500
committerMarc-Andre Lafortune <github@marc-andre.ca>2012-12-21 13:54:52 -0500
commit313232463d2a378cb3d14a34f5334cc4bd7a07b8 (patch)
tree6f0ef6a8632d3a08179004d8ae7d4fbb06ba621f /activerecord/lib
parente28ddea098d0422bae08324fb1d72f2b100152d0 (diff)
downloadrails-313232463d2a378cb3d14a34f5334cc4bd7a07b8.tar.gz
rails-313232463d2a378cb3d14a34f5334cc4bd7a07b8.tar.bz2
rails-313232463d2a378cb3d14a34f5334cc4bd7a07b8.zip
Make remove_index reversible [#8267]
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/migration/command_recorder.rb14
1 files changed, 10 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/migration/command_recorder.rb b/activerecord/lib/active_record/migration/command_recorder.rb
index 0fca1444f9..d61de6bc47 100644
--- a/activerecord/lib/active_record/migration/command_recorder.rb
+++ b/activerecord/lib/active_record/migration/command_recorder.rb
@@ -73,7 +73,7 @@ module ActiveRecord
[:create_table, :create_join_table, :change_table, :rename_table, :add_column, :remove_column,
:rename_index, :rename_column, :add_index, :remove_index, :add_timestamps, :remove_timestamps,
:change_column, :change_column_default, :add_reference, :remove_reference, :transaction,
- :drop_join_table, :drop_table, :remove_columns,
+ :drop_join_table, :drop_table, :remove_columns, :remove_index,
].each do |method|
class_eval <<-EOV, __FILE__, __LINE__ + 1
def #{method}(*args, &block) # def create_table(*args, &block)
@@ -132,9 +132,15 @@ module ActiveRecord
def invert_add_index(args)
table, columns, options = *args
- index_name = options.try(:[], :name)
- options_hash = index_name ? {:name => index_name} : {:column => columns}
- [:remove_index, [table, options_hash]]
+ [:remove_index, [table, (options || {}).merge(column: columns)]]
+ end
+
+ def invert_remove_index(args)
+ table, options = *args
+ raise ActiveRecord::IrreversibleMigration, "remove_index is only reversible if given a :column option." unless options && options[:column]
+
+ options = options.dup
+ [:add_index, [table, options.delete(:column), options]]
end
def invert_remove_timestamps(args)