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 0000000000000000000000000000000000000000..05401e363604c968ccfc01c0535634a75f9ef977 --- /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 0000000000000000000000000000000000000000..c09b001ff57cfb990a3ec3255cde518a4a013e90 --- /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 4c3ee5b8cebb1cb14690b16bdf0947b1b6e483b4..05fd042fb7b505054c8d923406299f392a0dcb68 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;