Commit 918e2c79 authored by Tiger's avatar Tiger Committed by Adam Hegyi

Change terraform_states.locked_by_user_id foreign key to SET NULL

Fixes an edge case where a user could not be deleted if they
held a lock (in the Terraform sense, not a database lock) on a
Terraform state, as it would violate the foreign key constraint.

https://gitlab.com/gitlab-org/gitlab/-/merge_requests/55813
parent 48e6b011
---
title: Change terraform_states.locked_by_user_id foreign key to SET NULL
merge_request: 55813
author:
type: fixed
# frozen_string_literal: true
class UpdateTerraformStatesLockedByUserIdForeignKey < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
OLD_FOREIGN_KEY = 'fk_rails_558901b030'
NEW_FOREIGN_KEY = 'fk_558901b030'
disable_ddl_transaction!
def up
add_concurrent_foreign_key :terraform_states, :users,
column: :locked_by_user_id, on_delete: :nullify, name: NEW_FOREIGN_KEY
with_lock_retries do
remove_foreign_key :terraform_states, :users, name: OLD_FOREIGN_KEY
end
end
def down
add_concurrent_foreign_key :terraform_states, :users,
column: :locked_by_user_id, on_delete: nil, name: OLD_FOREIGN_KEY
with_lock_retries do
remove_foreign_key :terraform_states, :users, name: NEW_FOREIGN_KEY
end
end
end
c91541048b119bcbbe9454760c6a90ddb6c4dc90e121f3ee7f4cdd6a1bde2c9e
\ No newline at end of file
......@@ -24451,6 +24451,9 @@ ALTER TABLE ONLY path_locks
ALTER TABLE ONLY clusters_applications_prometheus
ADD CONSTRAINT fk_557e773639 FOREIGN KEY (cluster_id) REFERENCES clusters(id) ON DELETE CASCADE;
ALTER TABLE ONLY terraform_states
ADD CONSTRAINT fk_558901b030 FOREIGN KEY (locked_by_user_id) REFERENCES users(id) ON DELETE SET NULL;
ALTER TABLE ONLY merge_request_metrics
ADD CONSTRAINT fk_56067dcb44 FOREIGN KEY (target_project_id) REFERENCES projects(id) ON DELETE CASCADE;
......@@ -25477,9 +25480,6 @@ ALTER TABLE ONLY geo_node_namespace_links
ALTER TABLE ONLY clusters_applications_knative
ADD CONSTRAINT fk_rails_54fc91e0a0 FOREIGN KEY (cluster_id) REFERENCES clusters(id) ON DELETE CASCADE;
ALTER TABLE ONLY terraform_states
ADD CONSTRAINT fk_rails_558901b030 FOREIGN KEY (locked_by_user_id) REFERENCES users(id);
ALTER TABLE ONLY issuable_metric_images
ADD CONSTRAINT fk_rails_56417a5a7f FOREIGN KEY (issue_id) REFERENCES issues(id) ON DELETE CASCADE;
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