Commit eed7ef45 authored by Patrick Bair's avatar Patrick Bair

Merge branch '283938-add-web_hooks-service-foreign-key' into 'master'

Add cascade delete foreign key web_hooks, services

See merge request gitlab-org/gitlab!47821
parents 91ea53ae 78e373c0
---
title: Add cascade delete foreign key to web_hooks on service_id without validation
merge_request: 47821
author:
type: fixed
# frozen_string_literal: true
class AddWebHooksServiceForeignKey < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
INDEX_NAME = 'index_web_hooks_on_service_id'
disable_ddl_transaction!
def up
add_concurrent_index :web_hooks, :service_id, name: INDEX_NAME
add_concurrent_foreign_key :web_hooks, :services, column: :service_id, on_delete: :cascade, validate: false
end
def down
with_lock_retries do
remove_foreign_key_if_exists :web_hooks, column: :service_id
end
remove_concurrent_index_by_name :web_hooks, INDEX_NAME
end
end
9fb3c338c999617b40e4c63f24ea037b5b1403354b93c2117e028ad8348d96aa
\ No newline at end of file
......@@ -22528,6 +22528,8 @@ CREATE INDEX index_web_hooks_on_group_id ON web_hooks USING btree (group_id) WHE
CREATE INDEX index_web_hooks_on_project_id ON web_hooks USING btree (project_id);
CREATE INDEX index_web_hooks_on_service_id ON web_hooks USING btree (service_id);
CREATE INDEX index_web_hooks_on_type ON web_hooks USING btree (type);
CREATE UNIQUE INDEX index_webauthn_registrations_on_credential_xid ON webauthn_registrations USING btree (credential_xid);
......@@ -23398,6 +23400,9 @@ ALTER TABLE ONLY environments
ALTER TABLE ONLY ci_builds
ADD CONSTRAINT fk_d3130c9a7f FOREIGN KEY (commit_id) REFERENCES ci_pipelines(id) ON DELETE CASCADE;
ALTER TABLE ONLY web_hooks
ADD CONSTRAINT fk_d47999a98a FOREIGN KEY (service_id) REFERENCES services(id) ON DELETE CASCADE NOT VALID;
ALTER TABLE ONLY ci_sources_pipelines
ADD CONSTRAINT fk_d4e29af7d7 FOREIGN KEY (source_pipeline_id) REFERENCES ci_pipelines(id) ON DELETE CASCADE;
......
......@@ -86,7 +86,7 @@ RSpec.describe 'Database schema' do
users_star_projects: %w[user_id],
vulnerability_identifiers: %w[external_id],
vulnerability_scanners: %w[external_id],
web_hooks: %w[service_id group_id]
web_hooks: %w[group_id]
}.with_indifferent_access.freeze
context 'for table' do
......
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