summaryrefslogtreecommitdiff
path: root/db/migrate/20221111142921_add_hierarchy_restrictions.rb
blob: dd80de0496993176f4a6305a0a8e995492968cf0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# frozen_string_literal: true

class AddHierarchyRestrictions < Gitlab::Database::Migration[2.0]
  UNIQUE_INDEX_NAME = 'index_work_item_hierarchy_restrictions_on_parent_and_child'

  def up
    create_table :work_item_hierarchy_restrictions do |t|
      t.references :parent_type, index: true, null: false,
                                 foreign_key: { on_delete: :cascade, to_table: :work_item_types }
      t.references :child_type, index: true, null: false,
                                foreign_key: { on_delete: :cascade, to_table: :work_item_types }
      t.integer :maximum_depth, limit: 2

      t.index [:parent_type_id, :child_type_id], unique: true, name: UNIQUE_INDEX_NAME
    end
  end

  def down
    drop_table :work_item_hierarchy_restrictions
  end
end