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

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

  INDEX_NAME = 'index_protected_branches_namespace_id'

  def up
    add_concurrent_index :protected_branches, :namespace_id, name: INDEX_NAME, where: 'namespace_id IS NOT NULL'
    add_concurrent_foreign_key :protected_branches, :namespaces, column: :namespace_id, on_delete: :cascade
  end

  def down
    with_lock_retries do
      remove_foreign_key :protected_branches, column: :namespace_id
    end
    remove_concurrent_index :protected_branches, :namespace_id, name: INDEX_NAME
  end
end