Swap FK ci_refs to projects for LFK

Swaps FK for ci_refs.project_id to projects

Changelog: changed
parent ea0d8ca9
# frozen_string_literal: true
class RemoveProjectsCiRefsProjectIdFk < Gitlab::Database::Migration[1.0]
disable_ddl_transaction!
def up
return if Gitlab.com? # unsafe migration, skip on GitLab.com due to https://gitlab.com/groups/gitlab-org/-/epics/7249#note_819625526
return unless foreign_key_exists?(:ci_refs, :projects, name: "fk_rails_4249db8cc3")
with_lock_retries do
execute('LOCK projects, ci_refs IN ACCESS EXCLUSIVE MODE') if transaction_open?
remove_foreign_key_if_exists(:ci_refs, :projects, name: "fk_rails_4249db8cc3")
end
end
def down
add_concurrent_foreign_key(:ci_refs, :projects, name: "fk_rails_4249db8cc3", column: :project_id, target_column: :id, on_delete: :cascade)
end
end
af60c6df0fb178a4820ea8cb40b402178da7fb4b6ebeabb8739dc45b96225f89
\ No newline at end of file
......@@ -30422,9 +30422,6 @@ ALTER TABLE ONLY geo_node_namespace_links
ALTER TABLE ONLY epic_issues
ADD CONSTRAINT fk_rails_4209981af6 FOREIGN KEY (issue_id) REFERENCES issues(id) ON DELETE CASCADE;
ALTER TABLE ONLY ci_refs
ADD CONSTRAINT fk_rails_4249db8cc3 FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE;
ALTER TABLE ONLY ci_resources
ADD CONSTRAINT fk_rails_430336af2d FOREIGN KEY (resource_group_id) REFERENCES ci_resource_groups(id) ON DELETE CASCADE;
......@@ -138,6 +138,10 @@ merge_trains:
- table: ci_pipelines
column: pipeline_id
on_delete: async_nullify
ci_refs:
- table: projects
column: project_id
on_delete: async_delete
ci_group_variables:
- table: namespaces
column: group_id
......
......@@ -28,7 +28,6 @@ RSpec.describe 'cross-database foreign keys' do
ci_pipelines.merge_request_id
ci_pipelines.project_id
ci_project_monthly_usages.project_id
ci_refs.project_id
ci_resource_groups.project_id
ci_runner_namespaces.namespace_id
ci_runner_projects.project_id
......
......@@ -231,4 +231,11 @@ RSpec.describe Ci::Ref do
it_behaves_like 'no-op'
end
end
context 'loose foreign key on ci_refs.project_id' do
it_behaves_like 'cleanup by a loose foreign key' do
let!(:parent) { create(:project) }
let!(:model) { create(:ci_ref, 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