Module: Gitlab::Database::RenameTableHelpers

Included in:
MigrationHelpers
Defined in:
lib/gitlab/database/rename_table_helpers.rb

Instance Method Summary collapse

Instance Method Details

#finalize_table_rename(old_table_name, new_table_name) ⇒ Object



20
21
22
23
24
# File 'lib/gitlab/database/rename_table_helpers.rb', line 20

def finalize_table_rename(old_table_name, new_table_name)
  transaction do
    execute("DROP VIEW IF EXISTS #{old_table_name}")
  end
end

#rename_table_safely(old_table_name, new_table_name) ⇒ Object



6
7
8
9
10
11
# File 'lib/gitlab/database/rename_table_helpers.rb', line 6

def rename_table_safely(old_table_name, new_table_name)
  transaction do
    rename_table(old_table_name, new_table_name)
    execute("CREATE VIEW #{old_table_name} AS SELECT * FROM #{new_table_name}")
  end
end

#undo_finalize_table_rename(old_table_name, new_table_name) ⇒ Object



26
27
28
29
30
# File 'lib/gitlab/database/rename_table_helpers.rb', line 26

def undo_finalize_table_rename(old_table_name, new_table_name)
  transaction do
    execute("CREATE VIEW #{old_table_name} AS SELECT * FROM #{new_table_name}")
  end
end

#undo_rename_table_safely(old_table_name, new_table_name) ⇒ Object



13
14
15
16
17
18
# File 'lib/gitlab/database/rename_table_helpers.rb', line 13

def undo_rename_table_safely(old_table_name, new_table_name)
  transaction do
    execute("DROP VIEW IF EXISTS #{old_table_name}")
    rename_table(new_table_name, old_table_name)
  end
end