diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-08-18 13:50:51 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-08-18 13:50:51 +0300 |
commit | db384e6b19af03b4c3c82a5760d83a3fd79f7982 (patch) | |
tree | 34beaef37df5f47ccbcf5729d7583aae093cffa0 /db/post_migrate/20230724085146_replace_old_fk_p_ci_builds_metadata_to_builds_v3.rb | |
parent | 54fd7b1bad233e3944434da91d257fa7f63c3996 (diff) |
Add latest changes from gitlab-org/gitlab@16-3-stable-eev16.3.0-rc42
Diffstat (limited to 'db/post_migrate/20230724085146_replace_old_fk_p_ci_builds_metadata_to_builds_v3.rb')
-rw-r--r-- | db/post_migrate/20230724085146_replace_old_fk_p_ci_builds_metadata_to_builds_v3.rb | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/db/post_migrate/20230724085146_replace_old_fk_p_ci_builds_metadata_to_builds_v3.rb b/db/post_migrate/20230724085146_replace_old_fk_p_ci_builds_metadata_to_builds_v3.rb new file mode 100644 index 00000000000..acfed3032eb --- /dev/null +++ b/db/post_migrate/20230724085146_replace_old_fk_p_ci_builds_metadata_to_builds_v3.rb @@ -0,0 +1,47 @@ +# frozen_string_literal: true + +class ReplaceOldFkPCiBuildsMetadataToBuildsV3 < Gitlab::Database::Migration[2.1] + include Gitlab::Database::PartitioningMigrationHelpers + + disable_ddl_transaction! + + def up + return if new_foreign_key_exists? + + with_lock_retries do + remove_foreign_key_if_exists :p_ci_builds_metadata, :ci_builds, + name: :fk_e20479742e_p, reverse_lock_order: true + + rename_constraint :p_ci_builds_metadata, :temp_fk_e20479742e_p, :fk_e20479742e_p + + Gitlab::Database::PostgresPartitionedTable.each_partition(:p_ci_builds_metadata) do |partition| + rename_constraint partition.identifier, :temp_fk_e20479742e_p, :fk_e20479742e_p + end + end + end + + def down + return unless new_foreign_key_exists? + + add_concurrent_partitioned_foreign_key :p_ci_builds_metadata, :ci_builds, + name: :temp_fk_e20479742e_p, + column: [:partition_id, :build_id], + target_column: [:partition_id, :id], + on_update: :cascade, + on_delete: :cascade, + validate: true, + reverse_lock_order: true + + switch_constraint_names :p_ci_builds_metadata, :fk_e20479742e_p, :temp_fk_e20479742e_p + + Gitlab::Database::PostgresPartitionedTable.each_partition(:p_ci_builds_metadata) do |partition| + switch_constraint_names partition.identifier, :fk_e20479742e_p, :temp_fk_e20479742e_p + end + end + + private + + def new_foreign_key_exists? + foreign_key_exists?(:p_ci_builds_metadata, :p_ci_builds, name: :fk_e20479742e_p) + end +end |