Commit a53e8998 authored by Drew Blessing's avatar Drew Blessing Committed by Adam Hegyi

Add missing ON DELETE FK constraints referencing users table

Issue 195699. The following tables were missing FK constraints
referencing the users table (user_id column) with cascading ON DELETE:

- protected_tag_create_access_levels
- protected_branch_merge_access_levels
- path_locks
- protected_branch_push_access_levels
- u2f_registrations
parent a0d178ab
---
title: Add missing ON DELETE FK constraints referencing users table
merge_request: 28720
author:
type: fixed
# frozen_string_literal: true
# rubocop: disable Migration/AddConcurrentForeignKey
class AddProtectedTagCreateAccessLevelsUserIdForeignKey < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
CONSTRAINT_NAME = 'fk_protected_tag_create_access_levels_user_id'
def up
with_lock_retries do
add_foreign_key(:protected_tag_create_access_levels, :users, on_delete: :cascade, validate: false, name: CONSTRAINT_NAME)
remove_foreign_key_if_exists(:protected_tag_create_access_levels, column: :user_id, on_delete: nil)
end
end
def down
fk_exists = foreign_key_exists?(:protected_tag_create_access_levels, :users, column: :user_id, on_delete: nil)
unless fk_exists
with_lock_retries do
add_foreign_key(:protected_tag_create_access_levels, :users, column: :user_id, validate: false)
end
end
remove_foreign_key_if_exists(:protected_tag_create_access_levels, column: :user_id, name: CONSTRAINT_NAME)
fk_name = concurrent_foreign_key_name(:protected_tag_create_access_levels, :user_id, prefix: 'fk_rails_')
validate_foreign_key(:protected_tag_create_access_levels, :user_id, name: fk_name)
end
end
# frozen_string_literal: true
class ValidateProtectedTagCreateAccessLevelsUserIdForeignKey < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
CONSTRAINT_NAME = 'fk_protected_tag_create_access_levels_user_id'
def up
validate_foreign_key :protected_tag_create_access_levels, :user_id, name: CONSTRAINT_NAME
end
def down
# no op
end
end
# frozen_string_literal: true
# rubocop: disable Migration/AddConcurrentForeignKey
class AddProtectedBranchMergeAccessLevelsUserIdForeignKey < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
CONSTRAINT_NAME = 'fk_protected_branch_merge_access_levels_user_id'
def up
with_lock_retries do
add_foreign_key(:protected_branch_merge_access_levels, :users, on_delete: :cascade, validate: false, name: CONSTRAINT_NAME)
remove_foreign_key_if_exists(:protected_branch_merge_access_levels, column: :user_id, on_delete: nil)
end
end
def down
fk_exists = foreign_key_exists?(:protected_branch_merge_access_levels, :users, column: :user_id, on_delete: nil)
unless fk_exists
with_lock_retries do
add_foreign_key(:protected_branch_merge_access_levels, :users, column: :user_id, validate: false)
end
end
remove_foreign_key_if_exists(:protected_branch_merge_access_levels, column: :user_id, name: CONSTRAINT_NAME)
fk_name = concurrent_foreign_key_name(:protected_branch_merge_access_levels, :user_id, prefix: 'fk_rails_')
validate_foreign_key(:protected_branch_merge_access_levels, :user_id, name: fk_name)
end
end
# frozen_string_literal: true
class ValidateProtectedBranchMergeAccessLevelsUserIdForeignKey < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
CONSTRAINT_NAME = 'fk_protected_branch_merge_access_levels_user_id'
def up
validate_foreign_key :protected_branch_merge_access_levels, :user_id, name: CONSTRAINT_NAME
end
def down
# no op
end
end
# frozen_string_literal: true
# rubocop: disable Migration/AddConcurrentForeignKey
class AddPathLocksUserIdForeignKey < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
CONSTRAINT_NAME = 'fk_path_locks_user_id'
def up
with_lock_retries do
add_foreign_key(:path_locks, :users, on_delete: :cascade, validate: false, name: CONSTRAINT_NAME)
remove_foreign_key_if_exists(:path_locks, column: :user_id, on_delete: nil)
end
end
def down
fk_exists = foreign_key_exists?(:path_locks, :users, column: :user_id, on_delete: nil)
unless fk_exists
with_lock_retries do
add_foreign_key(:path_locks, :users, column: :user_id, validate: false)
end
end
remove_foreign_key_if_exists(:path_locks, column: :user_id, name: CONSTRAINT_NAME)
fk_name = concurrent_foreign_key_name(:path_locks, :user_id, prefix: 'fk_rails_')
validate_foreign_key(:path_locks, :user_id, name: fk_name)
end
end
# frozen_string_literal: true
class ValidatePathLocksUserIdForeignKey < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
CONSTRAINT_NAME = 'fk_path_locks_user_id'
def up
validate_foreign_key :path_locks, :user_id, name: CONSTRAINT_NAME
end
def down
# no op
end
end
# frozen_string_literal: true
# rubocop: disable Migration/AddConcurrentForeignKey
class AddProtectedBranchPushAccessLevelsUserIdForeignKey < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
CONSTRAINT_NAME = 'fk_protected_branch_push_access_levels_user_id'
def up
with_lock_retries do
add_foreign_key(:protected_branch_push_access_levels, :users, on_delete: :cascade, validate: false, name: CONSTRAINT_NAME)
remove_foreign_key_if_exists(:protected_branch_push_access_levels, column: :user_id, on_delete: nil)
end
end
def down
fk_exists = foreign_key_exists?(:protected_branch_push_access_levels, :users, column: :user_id, on_delete: nil)
unless fk_exists
with_lock_retries do
add_foreign_key(:protected_branch_push_access_levels, :users, column: :user_id, validate: false)
end
end
remove_foreign_key_if_exists(:protected_branch_push_access_levels, column: :user_id, name: CONSTRAINT_NAME)
fk_name = concurrent_foreign_key_name(:protected_branch_push_access_levels, :user_id, prefix: 'fk_rails_')
validate_foreign_key(:protected_branch_push_access_levels, :user_id, name: fk_name)
end
end
# frozen_string_literal: true
class ValidateProtectedBranchPushAccessLevelsUserIdForeignKey < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
CONSTRAINT_NAME = 'fk_protected_branch_push_access_levels_user_id'
def up
validate_foreign_key :protected_branch_push_access_levels, :user_id, name: CONSTRAINT_NAME
end
def down
# no op
end
end
# frozen_string_literal: true
# rubocop: disable Migration/AddConcurrentForeignKey
class AddU2fRegistrationsUserIdForeignKey < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
CONSTRAINT_NAME = 'fk_u2f_registrations_user_id'
def up
with_lock_retries do
add_foreign_key(:u2f_registrations, :users, on_delete: :cascade, validate: false, name: CONSTRAINT_NAME)
remove_foreign_key_if_exists(:u2f_registrations, column: :user_id, on_delete: nil)
end
end
def down
fk_exists = foreign_key_exists?(:u2f_registrations, :users, column: :user_id, on_delete: nil)
unless fk_exists
with_lock_retries do
add_foreign_key(:u2f_registrations, :users, column: :user_id, validate: false)
end
end
remove_foreign_key_if_exists(:u2f_registrations, column: :user_id, name: CONSTRAINT_NAME)
fk_name = concurrent_foreign_key_name(:u2f_registrations, :user_id, prefix: 'fk_rails_')
validate_foreign_key(:u2f_registrations, :user_id, name: fk_name)
end
end
# frozen_string_literal: true
#
class ValidateU2fRegistrationsUserIdForeignKey < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
CONSTRAINT_NAME = 'fk_u2f_registrations_user_id'
def up
validate_foreign_key :u2f_registrations, :user_id, name: CONSTRAINT_NAME
end
def down
# no op
end
end
......@@ -11044,9 +11044,21 @@ ALTER TABLE ONLY public.issues
ALTER TABLE ONLY public.geo_event_log
ADD CONSTRAINT fk_geo_event_log_on_geo_event_id FOREIGN KEY (geo_event_id) REFERENCES public.geo_events(id) ON DELETE CASCADE;
ALTER TABLE ONLY public.path_locks
ADD CONSTRAINT fk_path_locks_user_id FOREIGN KEY (user_id) REFERENCES public.users(id) ON DELETE CASCADE;
ALTER TABLE ONLY public.personal_access_tokens
ADD CONSTRAINT fk_personal_access_tokens_user_id FOREIGN KEY (user_id) REFERENCES public.users(id) ON DELETE CASCADE;
ALTER TABLE ONLY public.protected_branch_merge_access_levels
ADD CONSTRAINT fk_protected_branch_merge_access_levels_user_id FOREIGN KEY (user_id) REFERENCES public.users(id) ON DELETE CASCADE;
ALTER TABLE ONLY public.protected_branch_push_access_levels
ADD CONSTRAINT fk_protected_branch_push_access_levels_user_id FOREIGN KEY (user_id) REFERENCES public.users(id) ON DELETE CASCADE;
ALTER TABLE ONLY public.protected_tag_create_access_levels
ADD CONSTRAINT fk_protected_tag_create_access_levels_user_id FOREIGN KEY (user_id) REFERENCES public.users(id) ON DELETE CASCADE;
ALTER TABLE ONLY public.approval_merge_request_rules
ADD CONSTRAINT fk_rails_004ce82224 FOREIGN KEY (merge_request_id) REFERENCES public.merge_requests(id) ON DELETE CASCADE;
......@@ -11191,9 +11203,6 @@ ALTER TABLE ONLY public.clusters_applications_runners
ALTER TABLE ONLY public.service_desk_settings
ADD CONSTRAINT fk_rails_223a296a85 FOREIGN KEY (project_id) REFERENCES public.projects(id) ON DELETE CASCADE;
ALTER TABLE ONLY public.protected_tag_create_access_levels
ADD CONSTRAINT fk_rails_2349b78b91 FOREIGN KEY (user_id) REFERENCES public.users(id);
ALTER TABLE ONLY public.group_custom_attributes
ADD CONSTRAINT fk_rails_246e0db83a FOREIGN KEY (group_id) REFERENCES public.namespaces(id) ON DELETE CASCADE;
......@@ -11440,9 +11449,6 @@ ALTER TABLE ONLY public.resource_weight_events
ALTER TABLE ONLY public.approval_project_rules
ADD CONSTRAINT fk_rails_5fb4dd100b FOREIGN KEY (project_id) REFERENCES public.projects(id) ON DELETE CASCADE;
ALTER TABLE ONLY public.protected_branch_merge_access_levels
ADD CONSTRAINT fk_rails_5ffb4f3590 FOREIGN KEY (user_id) REFERENCES public.users(id);
ALTER TABLE ONLY public.user_highest_roles
ADD CONSTRAINT fk_rails_60f6c325a6 FOREIGN KEY (user_id) REFERENCES public.users(id) ON DELETE CASCADE;
......@@ -11551,9 +11557,6 @@ ALTER TABLE ONLY public.geo_repositories_changed_events
ALTER TABLE ONLY public.resource_label_events
ADD CONSTRAINT fk_rails_75efb0a653 FOREIGN KEY (epic_id) REFERENCES public.epics(id) ON DELETE CASCADE;
ALTER TABLE ONLY public.path_locks
ADD CONSTRAINT fk_rails_762cdcf942 FOREIGN KEY (user_id) REFERENCES public.users(id);
ALTER TABLE ONLY public.x509_certificates
ADD CONSTRAINT fk_rails_76479fb5b4 FOREIGN KEY (x509_issuer_id) REFERENCES public.x509_issuers(id) ON DELETE CASCADE;
......@@ -11629,9 +11632,6 @@ ALTER TABLE ONLY public.vulnerability_feedback
ALTER TABLE ONLY public.approval_merge_request_rules_approved_approvers
ADD CONSTRAINT fk_rails_8dc94cff4d FOREIGN KEY (user_id) REFERENCES public.users(id) ON DELETE CASCADE;
ALTER TABLE ONLY public.protected_branch_push_access_levels
ADD CONSTRAINT fk_rails_8dcb712d65 FOREIGN KEY (user_id) REFERENCES public.users(id);
ALTER TABLE ONLY public.design_user_mentions
ADD CONSTRAINT fk_rails_8de8c6d632 FOREIGN KEY (note_id) REFERENCES public.notes(id) ON DELETE CASCADE;
......@@ -11842,9 +11842,6 @@ ALTER TABLE ONLY public.resource_weight_events
ALTER TABLE ONLY public.design_management_designs
ADD CONSTRAINT fk_rails_bfe283ec3c FOREIGN KEY (issue_id) REFERENCES public.issues(id) ON DELETE CASCADE;
ALTER TABLE ONLY public.u2f_registrations
ADD CONSTRAINT fk_rails_bfe6a84544 FOREIGN KEY (user_id) REFERENCES public.users(id);
ALTER TABLE ONLY public.serverless_domain_cluster
ADD CONSTRAINT fk_rails_c09009dee1 FOREIGN KEY (pages_domain_id) REFERENCES public.pages_domains(id) ON DELETE CASCADE;
......@@ -12079,6 +12076,9 @@ ALTER TABLE ONLY public.timelogs
ALTER TABLE ONLY public.timelogs
ADD CONSTRAINT fk_timelogs_merge_requests_merge_request_id FOREIGN KEY (merge_request_id) REFERENCES public.merge_requests(id) ON DELETE CASCADE;
ALTER TABLE ONLY public.u2f_registrations
ADD CONSTRAINT fk_u2f_registrations_user_id FOREIGN KEY (user_id) REFERENCES public.users(id) ON DELETE CASCADE;
COPY "schema_migrations" (version) FROM STDIN;
20171230123729
20180101160629
......@@ -13161,9 +13161,19 @@ COPY "schema_migrations" (version) FROM STDIN;
20200406193427
20200407094005
20200407094923
20200407171133
20200407171417
20200408110856
20200408133211
20200408153842
20200408154331
20200408154349
20200408154411
20200408154428
20200408154455
20200408154533
20200408154604
20200408154624
20200408175424
20200409211607
20200415160722
......
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