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

class AddNamespaceIndexOnTypeSync < Gitlab::Database::Migration[1.0]
  FULL_INDEX_NAME = 'index_namespaces_on_type_and_id'
  PARTIAL_INDEX_NAME = 'index_namespaces_on_type_and_id_partial'

  disable_ddl_transaction!

  def up
    add_concurrent_index :namespaces, [:type, :id], name: FULL_INDEX_NAME

    remove_concurrent_index_by_name :namespaces, name: PARTIAL_INDEX_NAME
  end

  def down
    add_concurrent_index(:namespaces, [:type, :id], where: 'type IS NOT NULL', name: PARTIAL_INDEX_NAME)

    remove_concurrent_index_by_name :namespaces, name: FULL_INDEX_NAME
  end
end