Commit 5e114952 authored by Furkan Ayhan's avatar Furkan Ayhan Committed by Adam Hegyi

Convert ci_builds-runner_id FK to LFK

Some runner_ids may be assigned to too many ci_builds so that deleting
them can cause downtime in the DB. So, we decided to convert this FK
to LFK.

Changelog: other
parent cf6d1a58
......@@ -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