From fcd1b33ee3ce186756da43c17aa291990e80b3b0 Mon Sep 17 00:00:00 2001 From: Max Orefice <morefice@gitlab.com> Date: Thu, 8 Feb 2024 11:12:04 +0000 Subject: [PATCH] Remove obsolete FK between ci_stages and p_ci_builds Changelog: other --- ...fk_to_ci_stages_p_ci_builds_on_stage_id.rb | 33 +++++++++++++++++++ db/schema_migrations/20240207094339 | 1 + db/structure.sql | 3 -- 3 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 db/post_migrate/20240207094339_remove_fk_to_ci_stages_p_ci_builds_on_stage_id.rb create mode 100644 db/schema_migrations/20240207094339 diff --git a/db/post_migrate/20240207094339_remove_fk_to_ci_stages_p_ci_builds_on_stage_id.rb b/db/post_migrate/20240207094339_remove_fk_to_ci_stages_p_ci_builds_on_stage_id.rb new file mode 100644 index 0000000000000..05401e363604c --- /dev/null +++ b/db/post_migrate/20240207094339_remove_fk_to_ci_stages_p_ci_builds_on_stage_id.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +class RemoveFkToCiStagesPCiBuildsOnStageId < Gitlab::Database::Migration[2.2] + include Gitlab::Database::PartitioningMigrationHelpers + + milestone '16.9' + disable_ddl_transaction! + + SOURCE_TABLE_NAME = :p_ci_builds + TARGET_TABLE_NAME = :ci_stages + FK_NAME = :fk_3a9eaa254d + + def up + with_lock_retries do + remove_foreign_key_if_exists( + SOURCE_TABLE_NAME, + TARGET_TABLE_NAME, + name: FK_NAME, + reverse_lock_order: true + ) + end + end + + def down + add_concurrent_partitioned_foreign_key( + SOURCE_TABLE_NAME, + TARGET_TABLE_NAME, + column: :stage_id, + on_delete: :cascade, + name: FK_NAME + ) + end +end diff --git a/db/schema_migrations/20240207094339 b/db/schema_migrations/20240207094339 new file mode 100644 index 0000000000000..c09b001ff57cf --- /dev/null +++ b/db/schema_migrations/20240207094339 @@ -0,0 +1 @@ +37ab5052429d2d1af66116f7a2dee32f140933e4a3e5b9c634e9023f24368c91 \ No newline at end of file diff --git a/db/structure.sql b/db/structure.sql index 4c3ee5b8cebb1..05fd042fb7b50 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -38554,9 +38554,6 @@ ALTER TABLE ONLY bulk_import_exports ALTER TABLE ONLY ml_model_versions ADD CONSTRAINT fk_39f8aa0b8a FOREIGN KEY (package_id) REFERENCES packages_packages(id) ON DELETE SET NULL; -ALTER TABLE p_ci_builds - ADD CONSTRAINT fk_3a9eaa254d FOREIGN KEY (stage_id) REFERENCES ci_stages(id) ON DELETE CASCADE; - ALTER TABLE p_ci_builds ADD CONSTRAINT fk_3a9eaa254d_p FOREIGN KEY (partition_id, stage_id) REFERENCES ci_stages(partition_id, id) ON UPDATE CASCADE ON DELETE CASCADE; -- GitLab