Class: DeclareSchema::SchemaChange::ColumnAdd

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

Direct Known Subclasses

ColumnRemove

Instance Method Summary collapse

Methods inherited from Base

#down, format_options, #up

Constructor Details

#initialize(table_name, column_name, column_type, **column_options) ⇒ ColumnAdd

Returns a new instance of ColumnAdd.



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

def initialize(table_name, column_name, column_type, **column_options)
  @table_name = table_name or raise ArgumentError, "must provide table_name"
  @column_name = column_name or raise ArgumentError, "must provide column_name"
  @column_type = column_type or raise ArgumentError, "must provide column_type"
  @column_options = column_options
end

Instance Method Details

#down_commandObject



22
23
24
# File 'lib/declare_schema/schema_change/column_add.rb', line 22

def down_command
  "remove_column #{@table_name.to_sym.inspect}, #{@column_name.to_sym.inspect}"
end

#up_commandObject



15
16
17
18
19
20
# File 'lib/declare_schema/schema_change/column_add.rb', line 15

def up_command
  "add_column #{[@table_name.to_sym.inspect,
                 @column_name.to_sym.inspect,
                 @column_type.to_sym.inspect,
                 *self.class.format_options(@column_options)].join(", ")}"
end