Commit 09f545c1 authored by Fabio Pitino's avatar Fabio Pitino

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

Swap FK to LFK ci_sources_pipelines to projects on source_project_id

See merge request gitlab-org/gitlab!78090
parents 9272fb9c 9f2dc374
# frozen_string_literal: true
class RemoveProjectsCiSourcesPipelinesSourceProjectIdFk < Gitlab::Database::Migration[1.0]
disable_ddl_transaction!
def up
with_lock_retries do
execute('LOCK projects, ci_sources_pipelines IN ACCESS EXCLUSIVE MODE')
remove_foreign_key_if_exists(:ci_sources_pipelines, :projects, name: "fk_acd9737679")
end
end
def down
add_concurrent_foreign_key(:ci_sources_pipelines, :projects, name: "fk_acd9737679", column: :source_project_id, target_column: :id, on_delete: :cascade)
end
end
a375f82fe0c1ef87aa6abb2142387b852b135be6e2158fd8456b23dc9bcf2a0e
\ No newline at end of file
......@@ -29690,9 +29690,6 @@ ALTER TABLE ONLY boards
ALTER TABLE ONLY member_tasks
ADD CONSTRAINT fk_ab636303dd FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE;
ALTER TABLE ONLY ci_sources_pipelines
ADD CONSTRAINT fk_acd9737679 FOREIGN KEY (source_project_id) REFERENCES projects(id) ON DELETE CASCADE;
ALTER TABLE ONLY merge_requests
ADD CONSTRAINT fk_ad525e1f87 FOREIGN KEY (merge_user_id) REFERENCES users(id) ON DELETE SET NULL;
......@@ -158,3 +158,7 @@ ci_pipeline_artifacts:
- table: projects
column: project_id
on_delete: async_delete
ci_sources_pipelines:
- table: projects
column: source_project_id
on_delete: async_delete
......@@ -34,7 +34,6 @@ RSpec.describe 'cross-database foreign keys' do
ci_runner_projects.project_id
ci_running_builds.project_id
ci_sources_pipelines.project_id
ci_sources_pipelines.source_project_id
ci_sources_projects.source_project_id
ci_stages.project_id
ci_subscriptions_projects.downstream_project_id
......
......@@ -17,4 +17,11 @@ RSpec.describe Ci::Sources::Pipeline do
it { is_expected.to validate_presence_of(:source_project) }
it { is_expected.to validate_presence_of(:source_job) }
it { is_expected.to validate_presence_of(:source_pipeline) }
context 'loose foreign key on ci_sources_pipelines.source_project_id' do
it_behaves_like 'cleanup by a loose foreign key' do
let!(:parent) { create(:project) }
let!(:model) { create(:ci_sources_pipeline, source_project: 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