aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/migration/command_recorder.rb
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2014-06-26 17:12:46 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2014-06-26 17:12:46 -0300
commitea93a15316d93896227c4c9d1ec5e47469575453 (patch)
treed766406aaefddedfc108297354e73bef80d95b06 /activerecord/lib/active_record/migration/command_recorder.rb
parent5add8b8d6d27afac9fe46bcee09cd341fb124294 (diff)
parenta5b3f372ab30e043d25b25b05e603e6ed33c0ee9 (diff)
downloadrails-ea93a15316d93896227c4c9d1ec5e47469575453.tar.gz
rails-ea93a15316d93896227c4c9d1ec5e47469575453.tar.bz2
rails-ea93a15316d93896227c4c9d1ec5e47469575453.zip
Merge pull request #15606 from senny/ar/foreign_key_support
Basic support for adding and removing foreign keys
Diffstat (limited to 'activerecord/lib/active_record/migration/command_recorder.rb')
-rw-r--r--activerecord/lib/active_record/migration/command_recorder.rb19
1 files changed, 18 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/migration/command_recorder.rb b/activerecord/lib/active_record/migration/command_recorder.rb
index c44d8c1665..f833caaab6 100644
--- a/activerecord/lib/active_record/migration/command_recorder.rb
+++ b/activerecord/lib/active_record/migration/command_recorder.rb
@@ -74,7 +74,9 @@ module ActiveRecord
:rename_index, :rename_column, :add_index, :remove_index, :add_timestamps, :remove_timestamps,
:change_column_default, :add_reference, :remove_reference, :transaction,
:drop_join_table, :drop_table, :execute_block, :enable_extension,
- :change_column, :execute, :remove_columns, :change_column_null # irreversible methods need to be here too
+ :change_column, :execute, :remove_columns, :change_column_null,
+ :add_foreign_key, :remove_foreign_key
+ # irreversible methods need to be here too
].each do |method|
class_eval <<-EOV, __FILE__, __LINE__ + 1
def #{method}(*args, &block) # def create_table(*args, &block)
@@ -167,6 +169,21 @@ module ActiveRecord
[:change_column_null, args]
end
+ def invert_add_foreign_key(args)
+ from_table, to_table, add_options = args
+ add_options ||= {}
+
+ if add_options[:name]
+ options = { name: add_options[:name] }
+ elsif add_options[:column]
+ options = { column: add_options[:column] }
+ else
+ options = to_table
+ end
+
+ [:remove_foreign_key, [from_table, options]]
+ end
+
# Forwards any missing method call to the \target.
def method_missing(method, *args, &block)
if @delegate.respond_to?(method)