aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/migration/command_recorder.rb
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2015-06-27 01:45:22 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2015-06-27 01:45:22 -0300
commit859c8c3f6727d000bd7fd12933c37b91fda3ad98 (patch)
tree5b8527a0b50419d84cc9564e309ec831096e27a7 /activerecord/lib/active_record/migration/command_recorder.rb
parente6035d1e08ff690437c30aeb54372602ae73b3f0 (diff)
parentf9c841927ac3d1daea2a9cebf08b18e844e5eec5 (diff)
downloadrails-859c8c3f6727d000bd7fd12933c37b91fda3ad98.tar.gz
rails-859c8c3f6727d000bd7fd12933c37b91fda3ad98.tar.bz2
rails-859c8c3f6727d000bd7fd12933c37b91fda3ad98.zip
Merge pull request #20018 from sikachu/change-column-default-recorder
Add reversible syntax for change_column_default
Diffstat (limited to 'activerecord/lib/active_record/migration/command_recorder.rb')
-rw-r--r--activerecord/lib/active_record/migration/command_recorder.rb12
1 files changed, 11 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/migration/command_recorder.rb b/activerecord/lib/active_record/migration/command_recorder.rb
index b592c004aa..dcc2362397 100644
--- a/activerecord/lib/active_record/migration/command_recorder.rb
+++ b/activerecord/lib/active_record/migration/command_recorder.rb
@@ -72,7 +72,7 @@ module ActiveRecord
[:create_table, :create_join_table, :rename_table, :add_column, :remove_column,
:rename_index, :rename_column, :add_index, :remove_index, :add_timestamps, :remove_timestamps,
- :change_column_default, :add_reference, :remove_reference, :transaction,
+ :add_reference, :remove_reference, :transaction,
:drop_join_table, :drop_table, :execute_block, :enable_extension,
:change_column, :execute, :remove_columns, :change_column_null,
:add_foreign_key, :remove_foreign_key
@@ -166,6 +166,16 @@ module ActiveRecord
alias :invert_add_belongs_to :invert_add_reference
alias :invert_remove_belongs_to :invert_remove_reference
+ def invert_change_column_default(args)
+ table, column, options = *args
+
+ unless options && options.is_a?(Hash) && options.has_key?(:from) && options.has_key?(:to)
+ raise ActiveRecord::IrreversibleMigration, "change_column_default is only reversible if given a :from and :to option."
+ end
+
+ [:change_column_default, [table, column, from: options[:to], to: options[:from]]]
+ end
+
def invert_change_column_null(args)
args[2] = !args[2]
[:change_column_null, args]