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

class AddIssuesNamespaceIdFkAndIndex < Gitlab::Database::Migration[2.0]
  disable_ddl_transaction!
  INDEX_NAME = 'index_issues_on_namespace_id'

  def up
    add_concurrent_index :issues, :namespace_id, name: INDEX_NAME
    add_concurrent_foreign_key :issues, :namespaces,
      column: :namespace_id,
      on_delete: :nullify,
      reverse_lock_order: true
  end

  def down
    with_lock_retries do
      remove_foreign_key_if_exists :issues, column: :namespace_id
    end

    remove_concurrent_index_by_name :issues, INDEX_NAME
  end
end