diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-08-18 13:50:51 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-08-18 13:50:51 +0300 |
commit | db384e6b19af03b4c3c82a5760d83a3fd79f7982 (patch) | |
tree | 34beaef37df5f47ccbcf5729d7583aae093cffa0 /db/post_migrate/20230728174927_add_epic_work_item_type.rb | |
parent | 54fd7b1bad233e3944434da91d257fa7f63c3996 (diff) |
Add latest changes from gitlab-org/gitlab@16-3-stable-eev16.3.0-rc42
Diffstat (limited to 'db/post_migrate/20230728174927_add_epic_work_item_type.rb')
-rw-r--r-- | db/post_migrate/20230728174927_add_epic_work_item_type.rb | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/db/post_migrate/20230728174927_add_epic_work_item_type.rb b/db/post_migrate/20230728174927_add_epic_work_item_type.rb new file mode 100644 index 00000000000..49f70e5379a --- /dev/null +++ b/db/post_migrate/20230728174927_add_epic_work_item_type.rb @@ -0,0 +1,82 @@ +# frozen_string_literal: true + +class AddEpicWorkItemType < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + restrict_gitlab_migration gitlab_schema: :gitlab_main + + ISSUE_ENUM_VALUE = 0 + EPIC_ENUM_VALUE = 7 + EPIC_NAME = 'Epic' + EPIC_WIDGETS = { + 'Assignees' => 0, + 'Description' => 1, + 'Hierarchy' => 2, + 'Labels' => 3, + 'Notes' => 5, + 'Start and due date' => 6, + 'Health status' => 7, + 'Status' => 11, + 'Notifications' => 14, + 'Award emoji' => 16 + }.freeze + + class MigrationWorkItemType < MigrationRecord + self.table_name = 'work_item_types' + end + + class MigrationWidgetDefinition < MigrationRecord + self.table_name = 'work_item_widget_definitions' + end + + class MigrationHierarchyRestriction < MigrationRecord + self.table_name = 'work_item_hierarchy_restrictions' + end + + def up + # New instances will not run this migration and add this type via fixtures + # checking if record exists mostly because migration specs will run all migrations + # and that will conflict with the preloaded base work item types + existing_epic_work_item_type = MigrationWorkItemType.find_by(base_type: EPIC_ENUM_VALUE, namespace_id: nil) + + return say('Epic work item type record exists, skipping creation') if existing_epic_work_item_type + + new_epic_work_item_type = MigrationWorkItemType.create( + name: EPIC_NAME, + namespace_id: nil, + base_type: EPIC_ENUM_VALUE, + icon_name: 'issue-type-epic' + ) + + widgets = EPIC_WIDGETS.map do |widget_name, widget_enum_value| + { + work_item_type_id: new_epic_work_item_type.id, + name: widget_name, + widget_type: widget_enum_value + } + end + + MigrationWidgetDefinition.upsert_all( + widgets, + unique_by: :index_work_item_widget_definitions_on_default_witype_and_name + ) + + issue_type = MigrationWorkItemType.find_by(base_type: ISSUE_ENUM_VALUE, namespace_id: nil) + return say('Issue work item type not found, skipping hierarchy restrictions creation') unless issue_type + + restrictions = [ + { parent_type_id: new_epic_work_item_type.id, child_type_id: new_epic_work_item_type.id, maximum_depth: 9 }, + { parent_type_id: new_epic_work_item_type.id, child_type_id: issue_type.id, maximum_depth: 1 } + ] + + MigrationHierarchyRestriction.upsert_all( + restrictions, + unique_by: :index_work_item_hierarchy_restrictions_on_parent_and_child + ) + end + + def down + # There's the remote possibility that issues could already be + # using this issue type, with a tight foreign constraint. + # Therefore we will not attempt to remove any data. + end +end |