Fix moving epics to a new group
What does this MR do and why?
Fix moving epics to a new group
When moving an epic to another group, we copy all the related data over to a new epic, or rather its related work item.
As part of the epic work item migration, every epic has a correlating work item (issue_id), and for some shared associations between the epics and the issues table, we still use the old epic_id OR the new issue_id.
Usually this is handled via a type column, like noteable_type and
notable_id. In the case of description_versions we either set the
epic_id or the issue_id in the column, and have a XOR NOT NULL
constraint.
So there are still many description_version records with an epic_id,
and when we copy over the data as part of moving the epic, we copied
over the epic_id AND the new work item issue_id. This resulted in a
database constraint check error, since we can't set both values at once.
This change fixes the copy mechanism by removing the epic_id when
copying the description_version attributes. The epic_id is no longer
needed, as we can associate it anyway with the new work item (issue_id).
Changelog: fixed EE: true
References
Issue: https://gitlab.com/gitlab-com/request-for-help/-/issues/3318 Sentry error: https://new-sentry.gitlab.net/organizations/gitlab/issues/1846374/?alert_rule_id=52&alert_type=issue&environment=gprd¬ification_uuid=cd5ea1b4-9daf-4549-8653-89efa217cf67&project=3&referrer=slack
Screenshots or screen recordings
| Before | After |
|---|---|
![]() |
![]() |
How to set up and validate locally
- Create an epic
- Change the description to generate a description versions (notable in the "Description changed" system note)
- Then modify the epic record to reproduce the state:
dv = DescriptionVersion.last dv.update!(issue_id: nil, epic_id: Epic.find_by_issue_id(dv.issue_id).id) - Move the epic to another group like
/move other-path - Before this MR: you see a 500 error, after this MR the move will be successful
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

