Class: DeclareSchema::SchemaChange::ColumnAdd
- Inherits:
-
Base
- Object
- Base
- DeclareSchema::SchemaChange::ColumnAdd
show all
- Defined in:
- lib/declare_schema/schema_change/column_add.rb
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
14
15
|
# File 'lib/declare_schema/schema_change/column_add.rb', line 8
def initialize(table_name, column_name, column_type, **column_options)
table_name.is_a?(String) || table_name.is_a?(Symbol) or raise ArgumentError, "must provide String|Symbol table_name; got #{table_name.inspect}"
column_name.is_a?(String) || column_name.is_a?(Symbol) or raise ArgumentError, "must provide String|Symbol column_name; got #{column_name.inspect}"
@table_name = table_name
@column_name = column_name
@column_type = column_type or raise ArgumentError, "must provide column_type"
@column_options = column_options
end
|
Instance Method Details
#down_command ⇒ Object
24
25
26
|
# File 'lib/declare_schema/schema_change/column_add.rb', line 24
def down_command
"remove_column #{@table_name.to_sym.inspect}, #{@column_name.to_sym.inspect}"
end
|
#up_command ⇒ Object
17
18
19
20
21
22
|
# File 'lib/declare_schema/schema_change/column_add.rb', line 17
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
|