Swap FK ci_subscriptions_projects to projects for LFK

Swaps FK for ci_subscriptions_projects.upstream_project_id to projects

Changelog: changed
parent 96be2cfd
# frozen_string_literal: true
class RemoveProjectsCiSubscriptionsProjectsUpstreamProjectIdFk < Gitlab::Database::Migration[1.0]
disable_ddl_transaction!
def up
return unless foreign_key_exists?(:ci_subscriptions_projects, :projects, name: "fk_rails_7871f9a97b")
with_lock_retries do
execute('LOCK projects, ci_subscriptions_projects IN ACCESS EXCLUSIVE MODE') if transaction_open?
remove_foreign_key_if_exists(:ci_subscriptions_projects, :projects, name: "fk_rails_7871f9a97b")
end
end
def down
add_concurrent_foreign_key(:ci_subscriptions_projects, :projects, name: "fk_rails_7871f9a97b", column: :upstream_project_id, target_column: :id, on_delete: :cascade)
end
end
ae696157794bcbe3ebd0dc41d7b3fe4dc61982ad4a96fa503fd7857e0d3dab16
\ No newline at end of file
......@@ -30755,9 +30755,6 @@ ALTER TABLE ONLY boards_epic_user_preferences
ALTER TABLE ONLY packages_debian_group_distribution_keys
ADD CONSTRAINT fk_rails_779438f163 FOREIGN KEY (distribution_id) REFERENCES packages_debian_group_distributions(id) ON DELETE CASCADE;
ALTER TABLE ONLY ci_subscriptions_projects
ADD CONSTRAINT fk_rails_7871f9a97b FOREIGN KEY (upstream_project_id) REFERENCES projects(id) ON DELETE CASCADE;
ALTER TABLE ONLY terraform_states
ADD CONSTRAINT fk_rails_78f54ca485 FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE;
......@@ -33,4 +33,11 @@ RSpec.describe Ci::Subscriptions::Project do
let!(:model) { create(:ci_subscriptions_project, downstream_project: parent) }
end
end
context 'loose foreign key on ci_subscriptions_projects.upstream_project_id' do
it_behaves_like 'cleanup by a loose foreign key' do
let!(:parent) { create(:project, :public) }
let!(:model) { create(:ci_subscriptions_project, upstream_project: parent) }
end
end
end
......@@ -172,6 +172,9 @@ ci_subscriptions_projects:
- table: projects
column: downstream_project_id
on_delete: async_delete
- table: projects
column: upstream_project_id
on_delete: async_delete
security_scans:
- table: ci_builds
column: build_id
......
......@@ -32,7 +32,6 @@ RSpec.describe 'cross-database foreign keys' do
ci_running_builds.project_id
ci_sources_projects.source_project_id
ci_stages.project_id
ci_subscriptions_projects.upstream_project_id
ci_unit_tests.project_id
dast_site_profiles_pipelines.ci_pipeline_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