summaryrefslogtreecommitdiff
path: root/lib/gitlab/database_importers/work_items/base_type_importer.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/database_importers/work_items/base_type_importer.rb')
-rw-r--r--lib/gitlab/database_importers/work_items/base_type_importer.rb14
1 files changed, 11 insertions, 3 deletions
diff --git a/lib/gitlab/database_importers/work_items/base_type_importer.rb b/lib/gitlab/database_importers/work_items/base_type_importer.rb
index 2d9700cb2bc..1e29ae7761b 100644
--- a/lib/gitlab/database_importers/work_items/base_type_importer.rb
+++ b/lib/gitlab/database_importers/work_items/base_type_importer.rb
@@ -4,10 +4,18 @@ module Gitlab
module DatabaseImporters
module WorkItems
module BaseTypeImporter
- def self.import
- ::WorkItems::Type::BASE_TYPES.each do |type, attributes|
- ::WorkItems::Type.create!(base_type: type, **attributes.slice(:name, :icon_name))
+ def self.upsert_types
+ current_time = Time.current
+
+ base_types = ::WorkItems::Type::BASE_TYPES.map do |type, attributes|
+ attributes.slice(:name, :icon_name)
+ .merge(created_at: current_time, updated_at: current_time, base_type: type)
end
+
+ ::WorkItems::Type.upsert_all(
+ base_types,
+ unique_by: :idx_work_item_types_on_namespace_id_and_name_null_namespace
+ )
end
end
end