Swap FK ci_sources_projects to projects for LFK

Swaps FK for ci_sources_projects.source_project_id to projects

Changelog: changed
parent 222c6089
# 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
......@@ -30607,9 +30607,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
......@@ -80,6 +80,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
......
......@@ -27,7 +27,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