Commit be6680c4 authored by Marius Bobin's avatar Marius Bobin

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

Swap FK ci_refs.project_id to projects for LFK

See merge request gitlab-org/gitlab!79065
parents 2870236a b35e6517
# frozen_string_literal: true
class RemoveProjectsCiRefsProjectIdFk < Gitlab::Database::Migration[1.0]
disable_ddl_transaction!
def up
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
......@@ -30413,9 +30413,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;
......@@ -145,6 +145,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
......
......@@ -27,7 +27,6 @@ RSpec.describe 'cross-database foreign keys' do
ci_pipeline_schedules.project_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