Investigate and remove orphaned project group links

Summary

Follow-up from !258506 (merged) to investigate and clean up orphaned project_group_links rows in the database.

Background

As identified in !258506 (merged), ProjectGroupLink rows can become orphaned in two ways:

  1. Invalid foreign key: The group_id foreign key to namespaces (fk_28a1244b01) is NOT VALID, so rows that predate it can still reference a namespace that no longer exists
  2. STI mismatch: belongs_to :group goes through the Group STI class, so a group_id that points at a namespace that is not a group (for example a user namespace) resolves to nil

While !258506 (merged) fixes the 500 error in the Groups API by gracefully handling these orphaned rows, the underlying data inconsistency remains.

Tasks

  • Investigate the scope of orphaned project_group_links rows in production
  • Determine if the orphaned rows can be safely deleted
  • Create a migration or background job to remove orphaned rows
  • Consider validating the fk_28a1244b01 foreign key constraint after cleanup
Edited by 🤖 GitLab Bot 🤖