Class: BazaMigrations::Commands::AddIndex
- Defined in:
- lib/baza_migrations/commands/add_index.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #changed_rollback_sql ⇒ Object
-
#initialize(table_name, columns, args) ⇒ AddIndex
constructor
A new instance of AddIndex.
- #sql ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(table_name, columns, args) ⇒ AddIndex
Returns a new instance of AddIndex.
2 3 4 5 6 |
# File 'lib/baza_migrations/commands/add_index.rb', line 2 def initialize(table_name, columns, args) @table_name = table_name @columns = columns @args = args end |
Instance Method Details
#changed_rollback_sql ⇒ Object
25 26 27 |
# File 'lib/baza_migrations/commands/add_index.rb', line 25 def changed_rollback_sql ["DROP INDEX `#{@db.escape_column(index_name)}`"] end |
#sql ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/baza_migrations/commands/add_index.rb', line 8 def sql sql = "CREATE" sql << " UNIQUE" if @args[:unique] sql << " INDEX `#{@db.escape_column(index_name)}` ON `#{@db.escape_table(@table_name)}` (" first = true columns_as_array.each do |column| sql << ", " unless first first = false if first sql << "`#{column}`" end sql << ")" [sql] end |