Update work items hierarchy restrictions records
What does this MR do and why?
In !132018 (merged) we added the column cross_hierarchy_enabled
to WorkItems::HierarchyRestrictions
table with a default value false
. In order to enable this attribute for epic-epic
and epic-issue
relationships, this MR adds a migration that sets this column as true
for the corresponding restriction records.
Database
UP
bin/rails db:migrate:up:main VERSION=20230918091159
WARNING: This version of GitLab depends on gitlab-shell 14.28.0, but you're running 14.26.0. Please update gitlab-shell.
main: == [advisory_lock_connection] object_id: 226660, pg_backend_pid: 15036
main: == 20230918091159 AddCrossHierarchyEnabledToHierarchyRestrictions: migrating ==
main: -- add_column(:work_item_hierarchy_restrictions, :cross_hierarchy_enabled, :boolean, {:default=>false, :null=>false})
main: -> 0.0033s
main: == 20230918091159 AddCrossHierarchyEnabledToHierarchyRestrictions: migrated (0.0066s)
main: == [advisory_lock_connection] object_id: 226660, pg_backend_pid: 15036
Query
INSERT INTO "work_item_hierarchy_restrictions" ("parent_type_id", "child_type_id", "maximum_depth", "cross_hierarchy_enabled")
VALUES (91413915, 91413915, 9, TRUE),
(91413915, 1, 1, TRUE)
ON CONFLICT ("parent_type_id", "child_type_id")
DO UPDATE SET
"maximum_depth" = excluded."maximum_depth", "cross_hierarchy_enabled" = excluded."cross_hierarchy_enabled"
RETURNING
"id"
Query plan: https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/22752/commands/73330
DOWN
bin/rails db:migrate:down:main VERSION=20230918091159
WARNING: This version of GitLab depends on gitlab-shell 14.28.0, but you're running 14.26.0. Please update gitlab-shell.
main: == [advisory_lock_connection] object_id: 226660, pg_backend_pid: 14484
main: == 20230918091159 AddCrossHierarchyEnabledToHierarchyRestrictions: reverting ==
main: -- remove_column(:work_item_hierarchy_restrictions, :cross_hierarchy_enabled, :boolean, {:default=>false, :null=>false})
main: -> 0.0039s
main: == 20230918091159 AddCrossHierarchyEnabledToHierarchyRestrictions: reverted (0.0080s)
main: == [advisory_lock_connection] object_id: 226660, pg_backend_pid: 14484
Query
INSERT INTO "work_item_hierarchy_restrictions" ("parent_type_id", "child_type_id", "maximum_depth", "cross_hierarchy_enabled")
VALUES (91413915, 91413915, 9, FALSE),
(91413915, 1, 1, FALSE)
ON CONFLICT ("parent_type_id", "child_type_id")
DO UPDATE SET
"maximum_depth" = excluded."maximum_depth", "cross_hierarchy_enabled" = excluded."cross_hierarchy_enabled"
RETURNING
"id"
Query plan: https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/22752/commands/73333
How to set up and validate locally
- In
master
branch open rails console and enable work items at the group level withFeature.enable(:namespace_level_work_items)
- Login and visit
https://GDK_URL/-/graphql-explorer
to create 3 work items. One should have the typeissue
and two the typeepic
. All items should be created in a different group.
mutations
# fetch WI type global ID for epic and issue and replace <workItemTypeId> if different
query gettWorkItemTypes {
project(fullPath: "gitlab-org/gitlab-test") {
id
workItemTypes {
nodes {
id
name
}
}
}
}
# Create each work item and take note of the ID
mutation createIssue {
workItemCreate(input: {namespacePath: "flightjs/Flight", title: "Work Item Type Issue", workItemTypeId: "gid://gitlab/WorkItems::Type/1"}) {
errors
workItem {
id
workItemType {
name
}
}
}
}
mutation createEpic1 {
workItemCreate(input: {namespacePath: "gitlab-org", title: "Work Item Type Epic 1", workItemTypeId: "gid://gitlab/WorkItems::Type/2992"}) {
errors
workItem {
id
workItemType {
name
}
}
}
}
mutation createEpic2 {
workItemCreate(input: {namespacePath: "h5bp", title: "Work Item Type Epic 2", workItemTypeId: "gid://gitlab/WorkItems::Type/2992"}) {
errors
workItem {
id
workItemType {
name
}
}
}
}
- Try to create the relationships and verify that an error is returned
mutations
mutation setIssueParent {
workItemUpdate(input: {id: "gid://gitlab/WorkItem/<issue_id>", hierarchyWidget: { parentId: "gid://gitlab/WorkItem/<epic_1_id>" }}) {
errors
workItem {
widgets {
... on WorkItemWidgetHierarchy {
parent {
title
id
}
}
}
}
}
}
mutation setEpicParent {
workItemUpdate(input: {id: "gid://gitlab/WorkItem/<epic_1_id>", hierarchyWidget: { parentId: "gid://gitlab/WorkItem/<epic_2_id>" }}) {
errors
workItem {
widgets {
... on WorkItemWidgetHierarchy {
parent {
title
id
}
}
}
}
}
}
error
{
"data": {
"workItemUpdate": {
"errors": [
"#39 cannot be added: parent must be in the same project or group as child."
],
"workItem": null
}
}
}
- Checkout this MR's branch
424896-allow-cross-group-work-items-hierarchy-2
, run migrations and attempt to create the relationships using the same mutations as step3
. Verify that parents are set.
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Related to #424896 (closed)
Edited by Eugenia Grieff