Commit d03a58f3 authored by Fabio Pitino's avatar Fabio Pitino

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

Swap FK ci_sources_projects.source_project_id to projects for LFK

See merge request gitlab-org/gitlab!79269
parents 462740c0 b01cf061
# frozen_string_literal: true
class RemoveProjectsCiSourcesProjectsSourceProjectIdFk < Gitlab::Database::Migration[1.0]
disable_ddl_transaction!
def up
return unless foreign_key_exists?(:ci_sources_projects, :projects, name: "fk_rails_64b6855cbc")
with_lock_retries do
execute('LOCK projects, ci_sources_projects IN ACCESS EXCLUSIVE MODE') if transaction_open?
remove_foreign_key_if_exists(:ci_sources_projects, :projects, name: "fk_rails_64b6855cbc")
end
end
def down
add_concurrent_foreign_key(:ci_sources_projects, :projects, name: "fk_rails_64b6855cbc", column: :source_project_id, target_column: :id, on_delete: :cascade)
end
end
6067e4e22e49548496454b48171f8168f7d5bf626fedab4351e2a37a3f85731b
\ No newline at end of file
......@@ -30603,9 +30603,6 @@ ALTER TABLE ONLY reviews
ALTER TABLE ONLY operations_feature_flags
ADD CONSTRAINT fk_rails_648e241be7 FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE;
ALTER TABLE ONLY ci_sources_projects
ADD CONSTRAINT fk_rails_64b6855cbc FOREIGN KEY (source_project_id) REFERENCES projects(id) ON DELETE CASCADE;
ALTER TABLE ONLY board_group_recent_visits
ADD CONSTRAINT fk_rails_64bfc19bc5 FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;
......@@ -13,4 +13,11 @@ RSpec.describe Ci::Sources::Project do
it { is_expected.to validate_uniqueness_of(:pipeline_id).scoped_to(:source_project_id) }
end
context 'loose foreign key on ci_sources_projects.source_project_id' do
it_behaves_like 'cleanup by a loose foreign key' do
let!(:parent) { create(:project) }
let!(:model) { create(:ci_sources_project, source_project: parent) }
end
end
end
......@@ -83,6 +83,10 @@ ci_namespace_mirrors:
- table: namespaces
column: namespace_id
on_delete: async_delete
ci_sources_projects:
- table: projects
column: source_project_id
on_delete: async_delete
ci_build_report_results:
- table: projects
column: project_id
......
......@@ -23,7 +23,6 @@ RSpec.describe 'cross-database foreign keys' do
ci_resource_groups.project_id
ci_runner_namespaces.namespace_id
ci_running_builds.project_id
ci_sources_projects.source_project_id
ci_stages.project_id
ci_unit_tests.project_id
).freeze
......
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