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:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-09-20 14:18:08 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-09-20 14:18:08 +0300
commit5afcbe03ead9ada87621888a31a62652b10a7e4f (patch)
tree9918b67a0d0f0bafa6542e839a8be37adf73102d /db/post_migrate/20230802212443_add_current_user_todos_widget_to_epic_work_item_type.rb
parentc97c0201564848c1f53226fe19d71fdcc472f7d0 (diff)
Add latest changes from gitlab-org/gitlab@16-4-stable-eev16.4.0-rc42
Diffstat (limited to 'db/post_migrate/20230802212443_add_current_user_todos_widget_to_epic_work_item_type.rb')
-rw-r--r--db/post_migrate/20230802212443_add_current_user_todos_widget_to_epic_work_item_type.rb56
1 files changed, 56 insertions, 0 deletions
diff --git a/db/post_migrate/20230802212443_add_current_user_todos_widget_to_epic_work_item_type.rb b/db/post_migrate/20230802212443_add_current_user_todos_widget_to_epic_work_item_type.rb
new file mode 100644
index 00000000000..958a5d6edb9
--- /dev/null
+++ b/db/post_migrate/20230802212443_add_current_user_todos_widget_to_epic_work_item_type.rb
@@ -0,0 +1,56 @@
+# frozen_string_literal: true
+
+class AddCurrentUserTodosWidgetToEpicWorkItemType < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+
+ EPIC_ENUM_VALUE = 7
+ WIDGET_NAME = 'Current user todos'
+ WIDGET_ENUM_VALUE = 15
+
+ class MigrationWorkItemType < MigrationRecord
+ self.table_name = 'work_item_types'
+ end
+
+ class MigrationWidgetDefinition < MigrationRecord
+ self.table_name = 'work_item_widget_definitions'
+ end
+
+ def up
+ epic_work_item_type = MigrationWorkItemType.find_by(base_type: EPIC_ENUM_VALUE, namespace_id: nil)
+
+ # Epic type should exist in production applications, checking here to avoid failures
+ # if inconsistent data is present.
+ return say('Epic work item type does not exist, skipping widget creation') unless epic_work_item_type
+
+ widgets = [
+ {
+ work_item_type_id: epic_work_item_type.id,
+ name: WIDGET_NAME,
+ widget_type: WIDGET_ENUM_VALUE
+ }
+ ]
+
+ MigrationWidgetDefinition.upsert_all(
+ widgets,
+ unique_by: :index_work_item_widget_definitions_on_default_witype_and_name
+ )
+ end
+
+ def down
+ epic_work_item_type = MigrationWorkItemType.find_by(base_type: EPIC_ENUM_VALUE, namespace_id: nil)
+
+ return say('Epic work item type does not exist, skipping widget removal') unless epic_work_item_type
+
+ widget_definition = MigrationWidgetDefinition.find_by(
+ work_item_type_id: epic_work_item_type.id,
+ widget_type: WIDGET_ENUM_VALUE,
+ name: WIDGET_NAME,
+ namespace_id: nil
+ )
+
+ return say('Widget definition not found, skipping widget removal') unless widget_definition
+
+ widget_definition.destroy
+ end
+end