Commit a44c5f5e authored by Fabio Pitino's avatar Fabio Pitino

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

Swap FK external_pull_requests.project_id to projects for LFK

See merge request gitlab-org/gitlab!79019
parents b98807a8 2dfceed9
# frozen_string_literal: true
class RemoveProjectsExternalPullRequestsProjectIdFk < Gitlab::Database::Migration[1.0]
disable_ddl_transaction!
def up
return unless foreign_key_exists?(:external_pull_requests, :projects, name: "fk_rails_bcae9b5c7b")
with_lock_retries do
execute('LOCK projects, external_pull_requests IN ACCESS EXCLUSIVE MODE') if transaction_open?
remove_foreign_key_if_exists(:external_pull_requests, :projects, name: "fk_rails_bcae9b5c7b")
end
end
def down
add_concurrent_foreign_key(:external_pull_requests, :projects, name: "fk_rails_bcae9b5c7b", column: :project_id, target_column: :id, on_delete: :cascade)
end
end
3b1f7a7b6481a960ac25523e5e1b5abc6c1436332d64d4319d9e4112b0fa765e
\ No newline at end of file
......@@ -31148,9 +31148,6 @@ ALTER TABLE ONLY projects_sync_events
ALTER TABLE ONLY approval_merge_request_rules_users
ADD CONSTRAINT fk_rails_bc8972fa55 FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;
ALTER TABLE ONLY external_pull_requests
ADD CONSTRAINT fk_rails_bcae9b5c7b FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE;
ALTER TABLE ONLY elasticsearch_indexed_projects
ADD CONSTRAINT fk_rails_bd13bbdc3d FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE;
......@@ -42,6 +42,10 @@ ci_daily_build_group_report_results:
- table: projects
column: project_id
on_delete: async_delete
external_pull_requests:
- table: projects
column: project_id
on_delete: async_delete
ci_freeze_periods:
- table: projects
column: project_id
......
......@@ -36,7 +36,6 @@ RSpec.describe 'cross-database foreign keys' do
ci_subscriptions_projects.upstream_project_id
ci_unit_tests.project_id
dast_site_profiles_pipelines.ci_pipeline_id
external_pull_requests.project_id
vulnerability_feedback.pipeline_id
).freeze
end
......
......@@ -236,4 +236,11 @@ RSpec.describe ExternalPullRequest do
it_behaves_like 'it has loose foreign keys' do
let(:factory_name) { :external_pull_request }
end
context 'loose foreign key on external_pull_requests.project_id' do
it_behaves_like 'cleanup by a loose foreign key' do
let!(:parent) { create(:project) }
let!(:model) { create(:external_pull_request, 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