Commit 59f4fa71 authored by Alex Kalderimis's avatar Alex Kalderimis

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

Swap FK dast_profiles_pipelines.ci_pipeline_id to ci_pipelines for LFK

See merge request gitlab-org/gitlab!78597
parents 138725b9 18f11e7f
# frozen_string_literal: true
class RemoveCiPipelinesDastProfilesPipelinesCiPipelineIdFk < Gitlab::Database::Migration[1.0]
disable_ddl_transaction!
def up
with_lock_retries do
execute('LOCK ci_pipelines, dast_profiles_pipelines IN ACCESS EXCLUSIVE MODE')
remove_foreign_key_if_exists(:dast_profiles_pipelines, :ci_pipelines, name: "fk_a60cad829d")
end
end
def down
add_concurrent_foreign_key(:dast_profiles_pipelines, :ci_pipelines, name: "fk_a60cad829d", column: :ci_pipeline_id, target_column: :id, on_delete: :cascade)
end
end
c991eda1b3a972a7da9bdbd5e1f9957394c52246b78d793b4b35fdec9daf6acd
\ No newline at end of file
......@@ -29665,9 +29665,6 @@ ALTER TABLE ONLY users
ALTER TABLE ONLY lfs_objects_projects
ADD CONSTRAINT fk_a56e02279c FOREIGN KEY (lfs_object_id) REFERENCES lfs_objects(id) ON DELETE RESTRICT NOT VALID;
ALTER TABLE ONLY dast_profiles_pipelines
ADD CONSTRAINT fk_a60cad829d FOREIGN KEY (ci_pipeline_id) REFERENCES ci_pipelines(id) ON DELETE CASCADE;
ALTER TABLE ONLY merge_requests
ADD CONSTRAINT fk_a6963e8447 FOREIGN KEY (target_project_id) REFERENCES projects(id) ON DELETE CASCADE;
......@@ -9,4 +9,11 @@ RSpec.describe Dast::ProfilesPipeline, type: :model do
it { is_expected.to belong_to(:ci_pipeline).class_name('Ci::Pipeline').required }
it { is_expected.to belong_to(:dast_profile).class_name('Dast::Profile').required }
end
context 'loose foreign key on dast_profiles_pipelines.ci_pipeline_id' do
it_behaves_like 'cleanup by a loose foreign key' do
let!(:parent) { create(:ci_pipeline) }
let!(:model) { create(:dast_profiles_pipeline, ci_pipeline: parent) }
end
end
end
......@@ -41,7 +41,6 @@ RSpec.describe 'cross-database foreign keys' do
ci_triggers.project_id
ci_unit_tests.project_id
ci_variables.project_id
dast_profiles_pipelines.ci_pipeline_id
dast_site_profiles_pipelines.ci_pipeline_id
external_pull_requests.project_id
vulnerability_feedback.pipeline_id
......
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