Class: BazaMigrations::Commands::RemoveColumn
- Defined in:
- lib/baza_migrations/commands/remove_column.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #changed_rollback_sql ⇒ Object
-
#initialize(table_name, column_name) ⇒ RemoveColumn
constructor
A new instance of RemoveColumn.
- #sql ⇒ Object
Methods inherited from Base
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_sql ⇒ Object
25 26 27 |
# File 'lib/baza_migrations/commands/remove_column.rb', line 25 def changed_rollback_sql raise BazaMigrations::Errors::IrreversibleMigration end |
#sql ⇒ Object
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 |