Class: BazaMigrations::Commands::RemoveColumn

Inherits:
Base
  • Object
show all
Defined in:
lib/baza_migrations/commands/remove_column.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) ⇒ RemoveColumn

Returns a new instance of RemoveColumn.



2
3
4
5
# File 'lib/baza_migrations/commands/remove_column.rb', line 2

def initialize(table_name, column_name)
  @table_name = table_name
  @column_name = column_name
end

Instance Method Details

#changed_rollback_sqlObject



25
26
27
# File 'lib/baza_migrations/commands/remove_column.rb', line 25

def changed_rollback_sql
  raise BazaMigrations::Errors::IrreversibleMigration
end

#sqlObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/baza_migrations/commands/remove_column.rb', line 7

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

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

      column = table.column(@column_name)
      column.drop
    end
  else
    sqls << "ALTER TABLE `#{@table_name}` DROP COLUMN `#{@column_name}`"
  end

  sqls
end