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

20230920154302_change_epics_hierarchy_restrictions.rb « post_migrate « db - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: eb1580712f5d8c6d5d606e7e3234403617122e33 (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# frozen_string_literal: true

class ChangeEpicsHierarchyRestrictions < Gitlab::Database::Migration[2.1]
  disable_ddl_transaction!

  restrict_gitlab_migration gitlab_schema: :gitlab_main

  class MigrationWorkItemType < MigrationRecord
    self.table_name = 'work_item_types'
  end

  class MigrationHierarchyRestriction < MigrationRecord
    self.table_name = 'work_item_hierarchy_restrictions'
  end

  def up
    upsert_epic_restrictions
  end

  def down
    upsert_epic_restrictions(stepping_down: true)
  end

  private

  def upsert_epic_restrictions(stepping_down: false)
    issue_type = MigrationWorkItemType.find_by_name_and_namespace_id('Issue', nil)
    epic_type = MigrationWorkItemType.find_by_name_and_namespace_id('Epic', nil)

    unless issue_type && epic_type
      Gitlab::AppLogger.warn('Issue or Epic work item types not found, skipping hierarchy restrictions update')

      return
    end

    restrictions = [
      {
        parent_type_id: epic_type.id,
        child_type_id: epic_type.id,
        maximum_depth: 9,
        cross_hierarchy_enabled: !stepping_down
      },
      {
        parent_type_id: epic_type.id,
        child_type_id: issue_type.id,
        maximum_depth: 1,
        cross_hierarchy_enabled: !stepping_down
      }
    ]

    MigrationHierarchyRestriction.reset_column_information
    MigrationHierarchyRestriction.upsert_all(
      restrictions,
      unique_by: :index_work_item_hierarchy_restrictions_on_parent_and_child
    )
  end
end