diff options
Diffstat (limited to 'db')
-rw-r--r-- | db/docs/work_item_types.yml | 1 | ||||
-rw-r--r-- | db/docs/work_item_widget_definitions.yml | 1 | ||||
-rw-r--r-- | db/migrate/20230228142350_add_notifications_work_item_widget.rb | 57 | ||||
-rw-r--r-- | db/schema_migrations/20230228142350 | 1 |
4 files changed, 60 insertions, 0 deletions
diff --git a/db/docs/work_item_types.yml b/db/docs/work_item_types.yml index 37d2c47de25..9c3da6a1b9d 100644 --- a/db/docs/work_item_types.yml +++ b/db/docs/work_item_types.yml @@ -1,6 +1,7 @@ --- table_name: work_item_types classes: +- AddNotificationsWorkItemWidget::WorkItemType - AddWidgetsForWorkItemTypes::WorkItemType - WorkItems::Type feature_categories: diff --git a/db/docs/work_item_widget_definitions.yml b/db/docs/work_item_widget_definitions.yml index 59cbca14908..a11fbfd34ae 100644 --- a/db/docs/work_item_widget_definitions.yml +++ b/db/docs/work_item_widget_definitions.yml @@ -1,6 +1,7 @@ --- table_name: work_item_widget_definitions classes: +- AddNotificationsWorkItemWidget::WidgetDefinition - AddWidgetsForWorkItemTypes::WidgetDefinition - WorkItems::WidgetDefinition feature_categories: diff --git a/db/migrate/20230228142350_add_notifications_work_item_widget.rb b/db/migrate/20230228142350_add_notifications_work_item_widget.rb new file mode 100644 index 00000000000..1bc89a6875c --- /dev/null +++ b/db/migrate/20230228142350_add_notifications_work_item_widget.rb @@ -0,0 +1,57 @@ +# frozen_string_literal: true + +class AddNotificationsWorkItemWidget < Gitlab::Database::Migration[2.1] + class WorkItemType < MigrationRecord + self.table_name = 'work_item_types' + end + + class WidgetDefinition < MigrationRecord + self.table_name = 'work_item_widget_definitions' + end + + restrict_gitlab_migration gitlab_schema: :gitlab_main + disable_ddl_transaction! + + WIDGET_NAME = 'Notifications' + WIDGET_ENUM_VALUE = 14 + WORK_ITEM_TYPES = [ + 'Issue', + 'Incident', + 'Test Case', + 'Requirement', + 'Task', + 'Objective', + 'Key Result' + ].freeze + + def up + widgets = [] + + WORK_ITEM_TYPES.each do |type_name| + type = WorkItemType.find_by_name_and_namespace_id(type_name, nil) + + unless type + Gitlab::AppLogger.warn("type #{type_name} is missing, not adding widget") + + next + end + + widgets << { + work_item_type_id: type.id, + name: WIDGET_NAME, + widget_type: WIDGET_ENUM_VALUE + } + end + + return if widgets.empty? + + WidgetDefinition.upsert_all( + widgets, + unique_by: :index_work_item_widget_definitions_on_default_witype_and_name + ) + end + + def down + WidgetDefinition.where(name: WIDGET_NAME).delete_all + end +end diff --git a/db/schema_migrations/20230228142350 b/db/schema_migrations/20230228142350 new file mode 100644 index 00000000000..cd783d44b2a --- /dev/null +++ b/db/schema_migrations/20230228142350 @@ -0,0 +1 @@ +ae4c6d6d477f073981f9f4e431bcb93289cfb54569a3dc982434a2e805c7801b
\ No newline at end of file |