Commit 27ce8211 authored by Kamil Trzciński's avatar Kamil Trzciński

Swap FK merge_requests to ci_pipelines for LFK

Swaps FK for merge_requests.head_pipeline_id to ci_pipelines

Changelog: changed
parent 6eec8e90
# 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
......@@ -30010,9 +30010,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;
......@@ -98,6 +98,9 @@ merge_requests:
- table: ci_pipelines
column: head_pipeline_id
on_delete: async_nullify
- table: ci_pipelines
column: head_pipeline_id
on_delete: async_nullify
vulnerability_statistics:
- table: ci_pipelines
column: latest_pipeline_id
......
......@@ -48,7 +48,6 @@ RSpec.describe 'cross-database foreign keys' do
dast_site_profiles_builds.ci_build_id
dast_site_profiles_pipelines.ci_pipeline_id
external_pull_requests.project_id
merge_requests.head_pipeline_id
merge_trains.pipeline_id
requirements_management_test_reports.build_id
security_scans.build_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