diff options
author | Yves Senn <yves.senn@gmail.com> | 2015-06-15 09:12:55 +0200 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2015-06-15 09:42:26 +0200 |
commit | 0e928de345a99a6173efbaa5c87e472dd86e4110 (patch) | |
tree | 26077c560e43ff7b2dc16caa4963e83119caefde /activerecord/lib/active_record/migration | |
parent | 863fcfa79ae625b891bbd4fbc86a7a1f9553dddd (diff) | |
download | rails-0e928de345a99a6173efbaa5c87e472dd86e4110.tar.gz rails-0e928de345a99a6173efbaa5c87e472dd86e4110.tar.bz2 rails-0e928de345a99a6173efbaa5c87e472dd86e4110.zip |
make `remove_index :table, :column` reversible.
This used to raise a `IrreversibleMigration` error (since #10437).
However since `remove_index :table, :column` is probably the most basic
use-case we should make it reversible again.
Conflicts:
activerecord/CHANGELOG.md
Diffstat (limited to 'activerecord/lib/active_record/migration')
-rw-r--r-- | activerecord/lib/active_record/migration/command_recorder.rb | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/migration/command_recorder.rb b/activerecord/lib/active_record/migration/command_recorder.rb index ee4545ed71..b592c004aa 100644 --- a/activerecord/lib/active_record/migration/command_recorder.rb +++ b/activerecord/lib/active_record/migration/command_recorder.rb @@ -151,14 +151,16 @@ module ActiveRecord end def invert_remove_index(args) - table, options = *args - - unless options && options.is_a?(Hash) && options[:column] - raise ActiveRecord::IrreversibleMigration, "remove_index is only reversible if given a :column option." + table, options_or_column = *args + if (options = options_or_column).is_a?(Hash) + unless options[:column] + raise ActiveRecord::IrreversibleMigration, "remove_index is only reversible if given a :column option." + end + options = options.dup + [:add_index, [table, options.delete(:column), options]] + elsif (column = options_or_column).present? + [:add_index, [table, column]] end - - options = options.dup - [:add_index, [table, options.delete(:column), options]] end alias :invert_add_belongs_to :invert_add_reference |