summaryrefslogtreecommitdiff
path: root/db/migrate/20210209110019_create_external_approval_rules.rb
blob: 5d6780ec41292ecbdf71592787bcd29b9a19330e (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
# frozen_string_literal: true

class CreateExternalApprovalRules < ActiveRecord::Migration[6.0]
  include Gitlab::Database::MigrationHelpers
  disable_ddl_transaction!

  DOWNTIME = false

  def up
    create_table_with_constraints :external_approval_rules, if_not_exists: true do |t|
      t.references :project, foreign_key: { on_delete: :cascade }, null: false, index: false
      t.timestamps_with_timezone
      t.text :external_url, null: false
      t.text_limit :external_url, 255
      t.text :name, null: false
      t.text_limit :name, 255

      t.index([:project_id, :name],
              unique: true,
              name: 'idx_on_external_approval_rules_project_id_name')
      t.index([:project_id, :external_url],
              unique: true,
              name: 'idx_on_external_approval_rules_project_id_external_url')
    end

    create_table :external_approval_rules_protected_branches do |t|
      t.bigint :external_approval_rule_id, null: false, index: { name: 'idx_eaprpb_external_approval_rule_id' }
      t.bigint :protected_branch_id, null: false
      t.index([:protected_branch_id, :external_approval_rule_id],
              unique: true,
              name: 'idx_protected_branch_id_external_approval_rule_id')
    end
  end

  def down
    with_lock_retries do
      drop_table :external_approval_rules_protected_branches, force: :cascade, if_exists: true
    end

    with_lock_retries do
      drop_table :external_approval_rules, force: :cascade, if_exists: true
    end
  end
end