Commit cc4b6bc3 authored by Marius Bobin's avatar Marius Bobin

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

Swap FK ci_subscriptions_projects.downstream_project_id to projects for LFK

See merge request gitlab-org/gitlab!79024
parents cf7126a3 8107fe95
# frozen_string_literal: true
class RemoveProjectsCiSubscriptionsProjectsDownstreamProjectIdFk < Gitlab::Database::Migration[1.0]
disable_ddl_transaction!
def up
return unless foreign_key_exists?(:ci_subscriptions_projects, :projects, name: "fk_rails_0818751483")
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_0818751483")
end
end
def down
add_concurrent_foreign_key(:ci_subscriptions_projects, :projects, name: "fk_rails_0818751483", column: :downstream_project_id, target_column: :id, on_delete: :cascade)
end
end
acf680cbf06d6eb2c0da44d416ff947e0460593cad74499acda91eb4bec63894
\ No newline at end of file
......@@ -30041,9 +30041,6 @@ ALTER TABLE ONLY ip_restrictions
ALTER TABLE ONLY terraform_state_versions
ADD CONSTRAINT fk_rails_04f176e239 FOREIGN KEY (terraform_state_id) REFERENCES terraform_states(id) ON DELETE CASCADE;
ALTER TABLE ONLY ci_subscriptions_projects
ADD CONSTRAINT fk_rails_0818751483 FOREIGN KEY (downstream_project_id) REFERENCES projects(id) ON DELETE CASCADE;
ALTER TABLE ONLY trending_projects
ADD CONSTRAINT fk_rails_09feecd872 FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE;
......@@ -26,4 +26,11 @@ RSpec.describe Ci::Subscriptions::Project do
expect(subscription).not_to be_valid
end
end
context 'loose foreign key on ci_subscriptions_projects.downstream_project_id' do
it_behaves_like 'cleanup by a loose foreign key' do
let!(:parent) { create(:project) }
let!(:model) { create(:ci_subscriptions_project, downstream_project: parent) }
end
end
end
......@@ -161,6 +161,10 @@ requirements_management_test_reports:
- table: ci_builds
column: build_id
on_delete: async_nullify
ci_subscriptions_projects:
- table: projects
column: downstream_project_id
on_delete: async_delete
security_scans:
- table: ci_builds
column: build_id
......
......@@ -33,7 +33,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.downstream_project_id
ci_subscriptions_projects.upstream_project_id
ci_unit_tests.project_id
dast_site_profiles_pipelines.ci_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