Class: Gitlab::Database::Migrations::SwapColumns

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/database/migrations/swap_columns.rb

Instance Method Summary collapse

Constructor Details

#initialize(migration_context:, table:, column1:, column2:) ⇒ SwapColumns

Returns a new instance of SwapColumns.



9
10
11
12
13
14
# File 'lib/gitlab/database/migrations/swap_columns.rb', line 9

def initialize(migration_context:, table:, column1:, column2:)
  @migration_context = migration_context
  @table = table
  @column_name1 = column1
  @column_name2 = column2
end

Instance Method Details

#executeObject



16
17
18
19
20
# File 'lib/gitlab/database/migrations/swap_columns.rb', line 16

def execute
  rename_column(@table, @column_name1, :temp_name_for_renaming)
  rename_column(@table, @column_name2, @column_name1)
  rename_column(@table, :temp_name_for_renaming, @column_name2)
end