Commit 16f5b43f authored by Marius Bobin's avatar Marius Bobin

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

Swap FK ci_job_token_project_scope_links.target_project_id to projects for LFK

See merge request gitlab-org/gitlab!79268
parents 7a142562 ed97fc57
# 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
...@@ -30647,9 +30647,6 @@ ALTER TABLE ONLY resource_iteration_events ...@@ -30647,9 +30647,6 @@ ALTER TABLE ONLY resource_iteration_events
ALTER TABLE ONLY geo_hashed_storage_migrated_events ALTER TABLE ONLY geo_hashed_storage_migrated_events
ADD CONSTRAINT fk_rails_687ed7d7c5 FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE; 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 ALTER TABLE ONLY plan_limits
ADD CONSTRAINT fk_rails_69f8b6184f FOREIGN KEY (plan_id) REFERENCES plans(id) ON DELETE CASCADE; 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: ...@@ -42,6 +42,9 @@ ci_job_token_project_scope_links:
- table: projects - table: projects
column: source_project_id column: source_project_id
on_delete: async_delete on_delete: async_delete
- table: projects
column: target_project_id
on_delete: async_delete
ci_daily_build_group_report_results: ci_daily_build_group_report_results:
- table: namespaces - table: namespaces
column: group_id column: group_id
......
...@@ -17,7 +17,6 @@ RSpec.describe 'cross-database foreign keys' do ...@@ -17,7 +17,6 @@ RSpec.describe 'cross-database foreign keys' do
ci_freeze_periods.project_id ci_freeze_periods.project_id
ci_job_artifacts.project_id ci_job_artifacts.project_id
ci_job_token_project_scope_links.added_by_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.namespace_id
ci_pending_builds.project_id ci_pending_builds.project_id
ci_pipeline_schedules.owner_id ci_pipeline_schedules.owner_id
......
...@@ -95,4 +95,11 @@ RSpec.describe Ci::JobToken::ProjectScopeLink do ...@@ -95,4 +95,11 @@ RSpec.describe Ci::JobToken::ProjectScopeLink do
let!(:model) { create(:ci_job_token_project_scope_link, source_project: parent) } let!(:model) { create(:ci_job_token_project_scope_link, source_project: parent) }
end end
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 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