Commit f4d7293c authored by Andreas Brandl's avatar Andreas Brandl

Remove with_lock_retries from RenameTableHelpers

Also update docs to suggest using lock-retries at the
migration level.
parent d1dc96a6
# frozen_string_literal: true # frozen_string_literal: true
class RenameInstanceStatisticsMeasurements < ActiveRecord::Migration[6.0] class RenameInstanceStatisticsMeasurements < Gitlab::Database::Migration[1.0]
include Gitlab::Database::MigrationHelpers enable_lock_retries!
def up def up
rename_table_safely(:analytics_instance_statistics_measurements, :analytics_usage_trends_measurements) rename_table_safely(:analytics_instance_statistics_measurements, :analytics_usage_trends_measurements)
......
# frozen_string_literal: true # frozen_string_literal: true
class RenameServicesToIntegrations < ActiveRecord::Migration[6.1] class RenameServicesToIntegrations < Gitlab::Database::Migration[1.0]
include Gitlab::Database::MigrationHelpers
include Gitlab::Database::SchemaHelpers include Gitlab::Database::SchemaHelpers
enable_lock_retries!
# Function and trigger names match those migrated in: # Function and trigger names match those migrated in:
# - https://gitlab.com/gitlab-org/gitlab/-/merge_requests/49916 # - https://gitlab.com/gitlab-org/gitlab/-/merge_requests/49916
# - https://gitlab.com/gitlab-org/gitlab/-/merge_requests/51852 # - https://gitlab.com/gitlab-org/gitlab/-/merge_requests/51852
......
...@@ -60,6 +60,8 @@ Consider the next release as "Release N.M". ...@@ -60,6 +60,8 @@ Consider the next release as "Release N.M".
Execute a standard migration (not a post-migration): Execute a standard migration (not a post-migration):
```ruby ```ruby
enable_lock_retries!
def up def up
rename_table_safely(:issues, :tickets) rename_table_safely(:issues, :tickets)
end end
......
...@@ -4,27 +4,27 @@ module Gitlab ...@@ -4,27 +4,27 @@ module Gitlab
module Database module Database
module RenameTableHelpers module RenameTableHelpers
def rename_table_safely(old_table_name, new_table_name) def rename_table_safely(old_table_name, new_table_name)
with_lock_retries do transaction do
rename_table(old_table_name, new_table_name) rename_table(old_table_name, new_table_name)
execute("CREATE VIEW #{old_table_name} AS SELECT * FROM #{new_table_name}") execute("CREATE VIEW #{old_table_name} AS SELECT * FROM #{new_table_name}")
end end
end end
def undo_rename_table_safely(old_table_name, new_table_name) def undo_rename_table_safely(old_table_name, new_table_name)
with_lock_retries do transaction do
execute("DROP VIEW IF EXISTS #{old_table_name}") execute("DROP VIEW IF EXISTS #{old_table_name}")
rename_table(new_table_name, old_table_name) rename_table(new_table_name, old_table_name)
end end
end end
def finalize_table_rename(old_table_name, new_table_name) def finalize_table_rename(old_table_name, new_table_name)
with_lock_retries do transaction do
execute("DROP VIEW IF EXISTS #{old_table_name}") execute("DROP VIEW IF EXISTS #{old_table_name}")
end end
end end
def undo_finalize_table_rename(old_table_name, new_table_name) def undo_finalize_table_rename(old_table_name, new_table_name)
with_lock_retries do transaction do
execute("CREATE VIEW #{old_table_name} AS SELECT * FROM #{new_table_name}") execute("CREATE VIEW #{old_table_name} AS SELECT * FROM #{new_table_name}")
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment