Class: BazaMigrations::Commands::RemoveIndex

Inherits:
Base
  • Object
show all
Defined in:
lib/baza_migrations/commands/remove_index.rb

Instance Attribute Summary

Attributes inherited from Base

#db, #table

Instance Method Summary collapse

Methods inherited from Base

#default_args

Constructor Details

#initialize(table_name, column_name) ⇒ RemoveIndex

Returns a new instance of RemoveIndex.



2
3
4
5
6
7
8
9
10
# File 'lib/baza_migrations/commands/remove_index.rb', line 2

def initialize(table_name, column_name)
  @table_name = table_name

  if column_name.is_a?(Array)
    @index_name = "index_#{@table_name}_on_#{column_name.join("_and_")}"
  else
    @index_name = "index_#{@table_name}_on_#{column_name}"
  end
end

Instance Method Details

#changed_rollback_sqlObject



30
31
32
# File 'lib/baza_migrations/commands/remove_index.rb', line 30

def changed_rollback_sql
  raise BazaMigrations::Errors::IrreversibleMigration
end

#sqlObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/baza_migrations/commands/remove_index.rb', line 12

def sql
  sqls = []
  db_type = db.opts.fetch(:type)

  if db_type.to_s.include?("sqlite3")
    sqls << proc do
      table = db.tables[@table_name]

      index = table.index(@index_name)
      index.drop
    end
  else
    sqls << "DROP INDEX `#{@index_name}` ON `#{@table_name}`"
  end

  sqls
end