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

20211126204445_add_task_to_work_item_types.rb « migrate « db - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 875c2272c6d010a27113f8a3e24e2f21a423f106 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# frozen_string_literal: true

class AddTaskToWorkItemTypes < Gitlab::Database::Migration[1.0]
  TASK_ENUM_VALUE = 4

  class WorkItemType < ActiveRecord::Base
    self.inheritance_column = :_type_disabled
    self.table_name = 'work_item_types'

    validates :name, uniqueness: { case_sensitive: false, scope: [:namespace_id] }
  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
    task_work_item = WorkItemType.find_by(name: 'Task', namespace_id: nil)

    if task_work_item
      say('Task item record exist, skipping creation')
    else
      WorkItemType.create(name: 'Task', namespace_id: nil, base_type: TASK_ENUM_VALUE, icon_name: 'issue-type-task')
    end
  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