diff options
Diffstat (limited to 'lib/gitlab/database/migration_helpers')
-rw-r--r-- | lib/gitlab/database/migration_helpers/swapping.rb | 50 | ||||
-rw-r--r-- | lib/gitlab/database/migration_helpers/v2.rb | 2 |
2 files changed, 51 insertions, 1 deletions
diff --git a/lib/gitlab/database/migration_helpers/swapping.rb b/lib/gitlab/database/migration_helpers/swapping.rb new file mode 100644 index 00000000000..6d19f8002d8 --- /dev/null +++ b/lib/gitlab/database/migration_helpers/swapping.rb @@ -0,0 +1,50 @@ +# frozen_string_literal: true + +module Gitlab + module Database + module MigrationHelpers + module Swapping + def reset_trigger_function(function_name) + execute("ALTER FUNCTION #{quote_table_name(function_name)} RESET ALL") + end + + def swap_columns(table, column1, column2) + ::Gitlab::Database::Migrations::SwapColumns.new( + migration_context: self, + table: table, + column1: column1, + column2: column2 + ).execute + end + + def swap_columns_default(table, column1, column2) + ::Gitlab::Database::Migrations::SwapColumnsDefault.new( + migration_context: self, + table: table, + column1: column1, + column2: column2 + ).execute + end + + def swap_foreign_keys(table, foreign_key1, foreign_key2) + rename_constraint(table, foreign_key1, :temp_name_for_renaming) + rename_constraint(table, foreign_key2, foreign_key1) + rename_constraint(table, :temp_name_for_renaming, foreign_key2) + end + + def swap_indexes(table, index1, index2) + identifier = "index_#{index1}_on_#{table}" + # Check Gitlab::Database::MigrationHelpers#concurrent_foreign_key_name() + # for info on why we use a hash + hashed_identifier = Digest::SHA256.hexdigest(identifier).first(10) + + temp_index = "temp_#{hashed_identifier}" + + rename_index(table, index1, temp_index) + rename_index(table, index2, index1) + rename_index(table, temp_index, index2) + end + end + end + end +end diff --git a/lib/gitlab/database/migration_helpers/v2.rb b/lib/gitlab/database/migration_helpers/v2.rb index 07e22963177..7cfafa1a6a6 100644 --- a/lib/gitlab/database/migration_helpers/v2.rb +++ b/lib/gitlab/database/migration_helpers/v2.rb @@ -43,7 +43,7 @@ module Gitlab end end - t.instance_eval(&block) unless block.nil? + yield t unless block.nil? end end |