Class: DeclareSchema::SchemaChange::IndexAdd
- Inherits:
-
Base
- Object
- Base
- DeclareSchema::SchemaChange::IndexAdd
show all
- Defined in:
- lib/declare_schema/schema_change/index_add.rb
Instance Method Summary
collapse
Methods inherited from Base
#down, format_options, #up
Constructor Details
#initialize(table_name, column_names, name:, unique:, where: nil) ⇒ IndexAdd
Returns a new instance of IndexAdd.
8
9
10
11
12
13
14
|
# File 'lib/declare_schema/schema_change/index_add.rb', line 8
def initialize(table_name, column_names, name:, unique:, where: nil)
@table_name = table_name
@column_names = column_names
@name = name
@unique = unique
@where = where.presence
end
|
Instance Method Details
#down_command ⇒ Object
28
29
30
|
# File 'lib/declare_schema/schema_change/index_add.rb', line 28
def down_command
"remove_index #{@table_name.to_sym.inspect}, name: #{@name.to_sym.inspect}"
end
|
#up_command ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/declare_schema/schema_change/index_add.rb', line 16
def up_command
options = {
name: @name.to_sym,
}
options[:unique] = true if @unique
options[:where] = @where if @where
"add_index #{[@table_name.to_sym.inspect,
@column_names.map(&:to_sym).inspect,
*self.class.format_options(options)].join(', ')}"
end
|