Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'db/post_migrate/20230920154302_change_epics_hierarchy_restrictions.rb')
-rw-r--r--db/post_migrate/20230920154302_change_epics_hierarchy_restrictions.rb57
1 files changed, 57 insertions, 0 deletions
diff --git a/db/post_migrate/20230920154302_change_epics_hierarchy_restrictions.rb b/db/post_migrate/20230920154302_change_epics_hierarchy_restrictions.rb
new file mode 100644
index 00000000000..eb1580712f5
--- /dev/null
+++ b/db/post_migrate/20230920154302_change_epics_hierarchy_restrictions.rb
@@ -0,0 +1,57 @@
+# frozen_string_literal: true
+
+class ChangeEpicsHierarchyRestrictions < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+
+ class MigrationWorkItemType < MigrationRecord
+ self.table_name = 'work_item_types'
+ end
+
+ class MigrationHierarchyRestriction < MigrationRecord
+ self.table_name = 'work_item_hierarchy_restrictions'
+ end
+
+ def up
+ upsert_epic_restrictions
+ end
+
+ def down
+ upsert_epic_restrictions(stepping_down: true)
+ end
+
+ private
+
+ def upsert_epic_restrictions(stepping_down: false)
+ issue_type = MigrationWorkItemType.find_by_name_and_namespace_id('Issue', nil)
+ epic_type = MigrationWorkItemType.find_by_name_and_namespace_id('Epic', nil)
+
+ unless issue_type && epic_type
+ Gitlab::AppLogger.warn('Issue or Epic work item types not found, skipping hierarchy restrictions update')
+
+ return
+ end
+
+ restrictions = [
+ {
+ parent_type_id: epic_type.id,
+ child_type_id: epic_type.id,
+ maximum_depth: 9,
+ cross_hierarchy_enabled: !stepping_down
+ },
+ {
+ parent_type_id: epic_type.id,
+ child_type_id: issue_type.id,
+ maximum_depth: 1,
+ cross_hierarchy_enabled: !stepping_down
+ }
+ ]
+
+ MigrationHierarchyRestriction.reset_column_information
+ MigrationHierarchyRestriction.upsert_all(
+ restrictions,
+ unique_by: :index_work_item_hierarchy_restrictions_on_parent_and_child
+ )
+ end
+end