Commit 884c10fe authored by Marius Bobin's avatar Marius Bobin

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

Swap FK ci_variables.project_id to projects for LFK

See merge request gitlab-org/gitlab!78946
parents e0de3533 f5feec0e
# frozen_string_literal: true
class RemoveProjectsCiVariablesProjectIdFk < Gitlab::Database::Migration[1.0]
disable_ddl_transaction!
def up
return unless foreign_key_exists?(:ci_variables, :projects, name: "fk_ada5eb64b3")
with_lock_retries do
execute('LOCK projects, ci_variables IN ACCESS EXCLUSIVE MODE') if transaction_open?
remove_foreign_key_if_exists(:ci_variables, :projects, name: "fk_ada5eb64b3")
end
end
def down
add_concurrent_foreign_key(:ci_variables, :projects, name: "fk_ada5eb64b3", column: :project_id, target_column: :id, on_delete: :cascade)
end
end
a1681c1c619db7f4e7e5a760cee7d06a931aa1f02dccfce46be81d75a03ce8ac
\ No newline at end of file
......@@ -29696,9 +29696,6 @@ ALTER TABLE ONLY member_tasks
ALTER TABLE ONLY merge_requests
ADD CONSTRAINT fk_ad525e1f87 FOREIGN KEY (merge_user_id) REFERENCES users(id) ON DELETE SET NULL;
ALTER TABLE ONLY ci_variables
ADD CONSTRAINT fk_ada5eb64b3 FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE;
ALTER TABLE ONLY merge_request_metrics
ADD CONSTRAINT fk_ae440388cc FOREIGN KEY (latest_closed_by_id) REFERENCES users(id) ON DELETE SET NULL;
......@@ -27,6 +27,10 @@ clusters_applications_runners:
- table: ci_runners
column: runner_id
on_delete: async_nullify
ci_variables:
- table: projects
column: project_id
on_delete: async_delete
ci_job_token_project_scope_links:
- table: users
column: added_by_id
......
......@@ -39,7 +39,6 @@ RSpec.describe 'cross-database foreign keys' do
ci_subscriptions_projects.downstream_project_id
ci_subscriptions_projects.upstream_project_id
ci_unit_tests.project_id
ci_variables.project_id
dast_site_profiles_pipelines.ci_pipeline_id
external_pull_requests.project_id
vulnerability_feedback.pipeline_id
......
......@@ -44,4 +44,11 @@ RSpec.describe Ci::Variable do
end
end
end
context 'loose foreign key on ci_variables.project_id' do
it_behaves_like 'cleanup by a loose foreign key' do
let!(:parent) { create(:project) }
let!(:model) { create(:ci_variable, 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