Skip to content

Add missing cascading deletes on foreign keys for group_id

Stan Hu requested to merge sh-fix-protected-access-levels-foreign-keys into master

It was possible to grant access to a group to do things to protected branches or tags, but if the group were deleted, the deletion might fail due to a message such as the following:

ActiveRecord::InvalidForeignKey: PG::ForeignKeyViolation: ERROR:  update or delete on table "namespaces" violates foreign key constraint "fk_rails_7111b68cdb" on table "protected_branch_push_access_levels"
DETAIL:  Key (id)=(1827859) is still referenced from table "protected_branch_push_access_levels".
: DELETE FROM "namespaces" WHERE "namespaces"."type" IN ('Group') AND "namespaces"."id" = 1827859

This MR fixes this by adding missing cascading deletions to the group_id foreign keys in the following tables:

  • protected_branch_merge_access_levels
  • protected_branch_push_access_levels
  • protected_tag_create_access_levels

Closes #3343 (closed), #3344 (closed), gitlab-org/gitlab-ce#37311

Merge request reports