Class: DeclareSchema::SchemaChange::ForeignKeyAdd

Inherits:
Base
  • Object
show all
Defined in:
lib/declare_schema/schema_change/foreign_key_add.rb

Direct Known Subclasses

ForeignKeyRemove

Instance Method Summary collapse

Methods inherited from Base

#down, format_options, #up

Constructor Details

#initialize(table_name, parent_table_name, column_name:, name:) ⇒ ForeignKeyAdd

Returns a new instance of ForeignKeyAdd.



8
9
10
11
12
13
# File 'lib/declare_schema/schema_change/foreign_key_add.rb', line 8

def initialize(table_name, parent_table_name, column_name:, name:)
  @table_name = table_name
  @parent_table_name = parent_table_name
  @column_name = column_name
  @name = name
end

Instance Method Details

#down_commandObject



20
21
22
# File 'lib/declare_schema/schema_change/foreign_key_add.rb', line 20

def down_command
  "remove_foreign_key #{@table_name.to_sym.inspect}, name: #{@name.to_sym.inspect}"
end

#up_commandObject



15
16
17
18
# File 'lib/declare_schema/schema_change/foreign_key_add.rb', line 15

def up_command
  "add_foreign_key #{@table_name.to_sym.inspect}, #{@parent_table_name.to_sym.inspect}, " +
    "column: #{@column_name.to_sym.inspect}, name: #{@name.to_sym.inspect}"
end