Commit 72310845 authored by Adam Hegyi's avatar Adam Hegyi

Merge branch '356153-convert-ci_builds-runner_id-fk-to-lfk' into 'master'

Convert ci_builds-runner_id FK to LFK

See merge request gitlab-org/gitlab!83129
parents 41e90a72 5e114952
......@@ -11,6 +11,9 @@ ci_builds:
- table: projects
column: project_id
on_delete: async_delete
- table: ci_runners
column: runner_id
on_delete: async_nullify
ci_builds_metadata:
- table: projects
column: project_id
......
# frozen_string_literal: true
class RemoveCiRunnersCiBuildsRunnerIdFk < Gitlab::Database::Migration[1.0]
disable_ddl_transaction!
def up
return unless foreign_key_exists?(:ci_builds, :ci_runners, name: "fk_e4ef9c2f27")
with_lock_retries do
execute('LOCK ci_runners, ci_builds IN ACCESS EXCLUSIVE MODE') if transaction_open?
remove_foreign_key_if_exists(:ci_builds, :ci_runners, name: "fk_e4ef9c2f27")
end
end
def down
add_concurrent_foreign_key :ci_builds, :ci_runners, name: "fk_e4ef9c2f27", column: :runner_id, target_column: :id, on_delete: :nullify, validate: false
end
end
94a8bc74fc935ba863d22b59b0ac6808bf5a9714c3759ca75a6dbee50c3c647d
\ No newline at end of file
......@@ -31696,9 +31696,6 @@ ALTER TABLE ONLY ci_builds_metadata
ALTER TABLE ONLY gitlab_subscriptions
ADD CONSTRAINT fk_e2595d00a1 FOREIGN KEY (namespace_id) REFERENCES namespaces(id) ON DELETE CASCADE;
ALTER TABLE ONLY ci_builds
ADD CONSTRAINT fk_e4ef9c2f27 FOREIGN KEY (runner_id) REFERENCES ci_runners(id) ON DELETE SET NULL NOT VALID;
ALTER TABLE ONLY merge_requests
ADD CONSTRAINT fk_e719a85f8a FOREIGN KEY (author_id) REFERENCES users(id) ON DELETE SET NULL;
......@@ -994,4 +994,11 @@ RSpec.describe CommitStatus do
let!(:model) { create(:ci_build, project: parent) }
end
end
context 'loose foreign key on ci_builds.runner_id' do
it_behaves_like 'cleanup by a loose foreign key' do
let!(:parent) { create(:ci_runner) }
let!(:model) { create(:ci_build, runner: 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