aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/migration/command_recorder.rb
diff options
context:
space:
mode:
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]