Swap FK ci_job_token_project_scope_links to projects for LFK

Swaps FK for ci_job_token_project_scope_links.target_project_id to projects

Changelog: changed
parent 222c6089
# frozen_string_literal: true
class RemoveProjectsCiJobTokenProjectScopeLinksTargetProjectIdFk < Gitlab::Database::Migration[1.0]
disable_ddl_transaction!
def up
return unless foreign_key_exists?(:ci_job_token_project_scope_links, :projects, name: "fk_rails_6904b38465")
with_lock_retries do
execute('LOCK projects, ci_job_token_project_scope_links IN ACCESS EXCLUSIVE MODE') if transaction_open?
remove_foreign_key_if_exists(:ci_job_token_project_scope_links, :projects, name: "fk_rails_6904b38465")
end
end
def down
add_concurrent_foreign_key(:ci_job_token_project_scope_links, :projects, name: "fk_rails_6904b38465", column: :target_project_id, target_column: :id, on_delete: :cascade)
end
end
7731772dfac065a60c1626707913ddf6ff632bb69dd5ed6534e8d29e4e03c573
\ No newline at end of file
......@@ -30649,9 +30649,6 @@ ALTER TABLE ONLY resource_iteration_events
ALTER TABLE ONLY geo_hashed_storage_migrated_events
ADD CONSTRAINT fk_rails_687ed7d7c5 FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE;
ALTER TABLE ONLY ci_job_token_project_scope_links
ADD CONSTRAINT fk_rails_6904b38465 FOREIGN KEY (target_project_id) REFERENCES projects(id) ON DELETE CASCADE;
ALTER TABLE ONLY plan_limits
ADD CONSTRAINT fk_rails_69f8b6184f FOREIGN KEY (plan_id) REFERENCES plans(id) ON DELETE CASCADE;
......@@ -42,6 +42,9 @@ ci_job_token_project_scope_links:
- table: projects
column: source_project_id
on_delete: async_delete
- table: projects
column: target_project_id
on_delete: async_delete
ci_daily_build_group_report_results:
- table: namespaces
column: group_id
......
......@@ -18,7 +18,6 @@ RSpec.describe 'cross-database foreign keys' do
ci_freeze_periods.project_id
ci_job_artifacts.project_id
ci_job_token_project_scope_links.added_by_id
ci_job_token_project_scope_links.target_project_id
ci_pending_builds.namespace_id
ci_pending_builds.project_id
ci_pipeline_schedules.owner_id
......
......@@ -95,4 +95,11 @@ RSpec.describe Ci::JobToken::ProjectScopeLink do
let!(:model) { create(:ci_job_token_project_scope_link, source_project: parent) }
end
end
context 'loose foreign key on ci_job_token_project_scope_links.target_project_id' do
it_behaves_like 'cleanup by a loose foreign key' do
let!(:parent) { create(:project) }
let!(:model) { create(:ci_job_token_project_scope_link, target_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