Skip to content

Fix orphaned and missing work item parent links

Nicolas Dular requested to merge nd/fix-orphaned-work-item-parent-links into master

What does this MR do and why?

Related issue: #465459

Fix orphaned work item parent links

When moving an issue we do the following:

  1. We close the initial issue A on the old project.
  2. We create a new issue B on the new project.
  3. We change the epic_issues relationship and update the epic_issues.issue_id to the ID of issue B.

We missed to sync step 3 to work_item_parent_links, and in addition to that, to update the namespace_id on work_item_parent_links.

epic_issues is still the SSoT and contains all epic<>issues relationships we need to sync. However, we have orphaned work_item_parent_links with the wrong work_item_id and namespace_id.

This is what we need to fix as part of the migration. Since the wrong syncing logic was never shipped to self managed instances, we can run the migration only on SaaS.

Changelog: fixed EE: true

Queries

I used the following query to find affected epics:

select
  epic_issues.epic_id
from
  epic_issues
  LEFT JOIN work_item_parent_links ON work_item_parent_links.work_item_id = epic_issues.issue_id
WHERE
  work_item_parent_links.work_item_id IS NULL
LIMIT
  10;
  1. Missing work item parent links
    1. With a match
    2. Without a match
  2. Orphaned (to delete) work item parent links
    1. With a match
    2. Without a match

Before

issues

id project_namespace_id Note
1 1 Old, closed issue
2 2 New, moved issue

epic_issues

issue_id epic_id
2 1

work_item_parent_links

work_item_id namespace_id
1 1

After

epic_issues (stays the same)

issue_id epic_id
2 1

work_item_parent_links

work_item_id namespace_id
2 2

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Before After

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

Edited by Nicolas Dular

Merge request reports