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:
- Invalid foreign key: The
group_idforeign key tonamespaces(fk_28a1244b01) isNOT VALID, so rows that predate it can still reference a namespace that no longer exists - STI mismatch:
belongs_to :groupgoes through theGroupSTI class, so agroup_idthat points at a namespace that is not a group (for example a user namespace) resolves tonil
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_linksrows 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_28a1244b01foreign key constraint after cleanup
Related
- Related MR: !258506 (merged)
- Related issue: #607090 (closed)
Edited by 🤖 GitLab Bot 🤖