summaryrefslogtreecommitdiff
path: root/db/migrate/20210804150320_create_base_work_item_types.rb
blob: b7a44eaabe0c8f44cfb79aeacd7d9ae2775b2601 (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
32
33
34
35
# frozen_string_literal: true

class CreateBaseWorkItemTypes < ActiveRecord::Migration[6.1]
  include Gitlab::Database::MigrationHelpers

  module WorkItem
    class Type < ActiveRecord::Base
      self.table_name = 'work_item_types'

      enum base_type: {
        issue:       0,
        incident:    1,
        test_case:   2,
        requirement: 3
      }

      validates :name, uniqueness: { case_sensitive: false, scope: [:namespace_id] }
    end
  end

  def up
    # create default types
    WorkItem::Type.create(name: 'Issue', namespace_id: nil, base_type: :issue, icon_name: 'issue-type-issue')
    WorkItem::Type.create(name: 'Incident', namespace_id: nil, base_type: :incident, icon_name: 'issue-type-incident')
    WorkItem::Type.create(name: 'Test Case', namespace_id: nil, base_type: :test_case, icon_name: 'issue-type-test-case')
    WorkItem::Type.create(name: 'Requirement', namespace_id: nil, base_type: :requirement, icon_name: 'issue-type-requirements')
  end

  def down
    # We expect this table to be empty at the point of the up migration,
    # however there is a remote possibility that issues could already be
    # using one of these types, with a tight foreign constraint.
    # Therefore we will not attempt to remove any data.
  end
end