summaryrefslogtreecommitdiff
path: root/db/migrate/20220613112031_add_group_or_project_constraint_in_protected_branches.rb
blob: b7f204504807f5030a7bfc0893ffe4648ff2ba0d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# frozen_string_literal: true

class AddGroupOrProjectConstraintInProtectedBranches < Gitlab::Database::Migration[2.0]
  disable_ddl_transaction!

  CONSTRAINT_NAME = 'protected_branches_project_id_namespace_id_any_not_null'

  def up
    constraint = <<~CONSTRAINT
      (project_id IS NULL) <> (namespace_id IS NULL)
    CONSTRAINT
    add_check_constraint :protected_branches, constraint, CONSTRAINT_NAME
  end

  def down
    remove_check_constraint :protected_branches, CONSTRAINT_NAME
  end
end