Commit cd5c5865 authored by Fabio Pitino's avatar Fabio Pitino

Merge branch 'remove-ci_pipelines_merge_requests_head_pipeline_id-fk' into 'master'

Swap FK merge_requests.head_pipeline_id to ci_pipelines for LFK

See merge request gitlab-org/gitlab!78566
parents e3fd22d4 1dc8e795
# frozen_string_literal: true
class RemoveCiPipelinesMergeRequestsHeadPipelineIdFk < Gitlab::Database::Migration[1.0]
disable_ddl_transaction!
def up
with_lock_retries do
execute('LOCK ci_pipelines, merge_requests IN ACCESS EXCLUSIVE MODE')
remove_foreign_key_if_exists(:merge_requests, :ci_pipelines, name: "fk_fd82eae0b9")
end
end
def down
add_concurrent_foreign_key(:merge_requests, :ci_pipelines, name: "fk_fd82eae0b9", column: :head_pipeline_id, target_column: :id, on_delete: :nullify)
end
end
7cb06f695c7e8e733ea50f0b2e8fbb115d5ac0d7e7f000228bd5ced58ab362c9
\ No newline at end of file
......@@ -29999,9 +29999,6 @@ ALTER TABLE ONLY system_note_metadata
ALTER TABLE ONLY vulnerability_remediations
ADD CONSTRAINT fk_fc61a535a0 FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE;
ALTER TABLE ONLY merge_requests
ADD CONSTRAINT fk_fd82eae0b9 FOREIGN KEY (head_pipeline_id) REFERENCES ci_pipelines(id) ON DELETE SET NULL;
ALTER TABLE ONLY project_import_data
ADD CONSTRAINT fk_ffb9ee3a10 FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE;
......@@ -44,7 +44,6 @@ RSpec.describe 'cross-database foreign keys' do
dast_profiles_pipelines.ci_pipeline_id
dast_site_profiles_pipelines.ci_pipeline_id
external_pull_requests.project_id
merge_requests.head_pipeline_id
merge_trains.pipeline_id
vulnerability_feedback.pipeline_id
vulnerability_occurrence_pipelines.pipeline_id
......
......@@ -4965,4 +4965,11 @@ RSpec.describe MergeRequest, factory_default: :keep do
it_behaves_like 'it has loose foreign keys' do
let(:factory_name) { :merge_request }
end
context 'loose foreign key on merge_requests.head_pipeline_id' do
it_behaves_like 'cleanup by a loose foreign key' do
let!(:parent) { create(:ci_pipeline) }
let!(:model) { create(:merge_request, head_pipeline: parent) }
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