2021-06-08 01:23:25 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Database
|
|
|
|
module RenameTableHelpers
|
|
|
|
def rename_table_safely(old_table_name, new_table_name)
|
2021-11-11 11:23:49 +05:30
|
|
|
transaction do
|
2021-06-08 01:23:25 +05:30
|
|
|
rename_table(old_table_name, new_table_name)
|
|
|
|
execute("CREATE VIEW #{old_table_name} AS SELECT * FROM #{new_table_name}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def undo_rename_table_safely(old_table_name, new_table_name)
|
2021-11-11 11:23:49 +05:30
|
|
|
transaction do
|
2021-06-08 01:23:25 +05:30
|
|
|
execute("DROP VIEW IF EXISTS #{old_table_name}")
|
|
|
|
rename_table(new_table_name, old_table_name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def finalize_table_rename(old_table_name, new_table_name)
|
2021-11-11 11:23:49 +05:30
|
|
|
transaction do
|
2021-06-08 01:23:25 +05:30
|
|
|
execute("DROP VIEW IF EXISTS #{old_table_name}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def undo_finalize_table_rename(old_table_name, new_table_name)
|
2021-11-11 11:23:49 +05:30
|
|
|
transaction do
|
2021-06-08 01:23:25 +05:30
|
|
|
execute("CREATE VIEW #{old_table_name} AS SELECT * FROM #{new_table_name}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|