Module: PgPower::Migration::CommandRecorder::ForeignerMethods

Included in:
PgPower::Migration::CommandRecorder
Defined in:
lib/pg_power/migration/command_recorder/foreigner_methods.rb

Overview

Provides methods to extend ActiveRecord::Migration::CommandRecorder to support foreign keys feature.

Instance Method Summary collapse

Instance Method Details

#add_foreign_key(*args) ⇒ Object

:nodoc:



5
6
7
# File 'lib/pg_power/migration/command_recorder/foreigner_methods.rb', line 5

def add_foreign_key(*args)
  record(:add_foreign_key, args)
end

#invert_add_foreign_key(args) ⇒ Object

:nodoc:



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/pg_power/migration/command_recorder/foreigner_methods.rb', line 15

def invert_add_foreign_key(args)
  from_table, to_table, add_options = *args
  add_options ||= {}
  add_name_option   = add_options[:name]
  add_column_option = add_options[:column]

  if add_name_option then
    options = {:name => add_name_option}
  elsif add_column_option
    options = {:column => add_column_option}
  else
    options = to_table
  end

  [:remove_foreign_key, [from_table, options]]
end

#remove_foreign_key(*args) ⇒ Object

:nodoc:



10
11
12
# File 'lib/pg_power/migration/command_recorder/foreigner_methods.rb', line 10

def remove_foreign_key(*args)
  record(:remove_foreign_key, args)
end