diff --git a/changelogs/unreleased/202423-foreign-key-webhooks-groups.yml b/changelogs/unreleased/202423-foreign-key-webhooks-groups.yml new file mode 100644 index 0000000000000000000000000000000000000000..bb1f0de8eb4f32ebd39d2a12307e812b88be17ea --- /dev/null +++ b/changelogs/unreleased/202423-foreign-key-webhooks-groups.yml @@ -0,0 +1,5 @@ +--- +title: Add foreign key from web_hooks to groups +merge_request: 57735 +author: +type: other diff --git a/db/migrate/20210325092215_add_not_valid_foreign_key_to_group_hooks.rb b/db/migrate/20210325092215_add_not_valid_foreign_key_to_group_hooks.rb new file mode 100644 index 0000000000000000000000000000000000000000..2389f90d498fe02ee1c45e38977826b5b7bf382c --- /dev/null +++ b/db/migrate/20210325092215_add_not_valid_foreign_key_to_group_hooks.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class AddNotValidForeignKeyToGroupHooks < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + def up + with_lock_retries do + add_foreign_key :web_hooks, :namespaces, column: :group_id, on_delete: :cascade, validate: false + end + end + + def down + with_lock_retries do + remove_foreign_key_if_exists :web_hooks, column: :group_id + end + end +end diff --git a/db/schema_migrations/20210325092215 b/db/schema_migrations/20210325092215 new file mode 100644 index 0000000000000000000000000000000000000000..0693c47994b48d5d72e873581f0d9feef1a9288b --- /dev/null +++ b/db/schema_migrations/20210325092215 @@ -0,0 +1 @@ +ea819fd401c5566986fd495ed3b8aa0d296d6c9e3fedf2a10f34cb7fbaeedb20 \ No newline at end of file diff --git a/db/structure.sql b/db/structure.sql index 96e1a788f315125dec2a9db19f92660036205f3b..836122f6097262f18792c4fc11bd32dc847d8046 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -26571,6 +26571,9 @@ ALTER TABLE ONLY requirements_management_test_reports ALTER TABLE ONLY pool_repositories ADD CONSTRAINT fk_rails_d2711daad4 FOREIGN KEY (source_project_id) REFERENCES projects(id) ON DELETE SET NULL; +ALTER TABLE ONLY web_hooks + ADD CONSTRAINT fk_rails_d35697648e FOREIGN KEY (group_id) REFERENCES namespaces(id) ON DELETE CASCADE NOT VALID; + ALTER TABLE ONLY group_group_links ADD CONSTRAINT fk_rails_d3a0488427 FOREIGN KEY (shared_group_id) REFERENCES namespaces(id) ON DELETE CASCADE; diff --git a/spec/db/schema_spec.rb b/spec/db/schema_spec.rb index d292ba60a121131a5d484db62b6e218828c2da38..0d8407dd7faccdb1c6b03e589de2768c6dac8153 100644 --- a/spec/db/schema_spec.rb +++ b/spec/db/schema_spec.rb @@ -87,7 +87,6 @@ users_star_projects: %w[user_id], vulnerability_identifiers: %w[external_id], vulnerability_scanners: %w[external_id], - web_hooks: %w[group_id], web_hook_logs_part_0c5294f417: %w[web_hook_id] }.with_indifferent_access.freeze