summaryrefslogtreecommitdiff
path: root/db/migrate/20201120125953_replace_unused_labels_index.rb
blob: afddbce618d45afb23c6cfd1cceda5c7015adee9 (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 ReplaceUnusedLabelsIndex < ActiveRecord::Migration[6.0]
  include Gitlab::Database::MigrationHelpers

  DOWNTIME = false

  disable_ddl_transaction!

  NEW_INDEX_NAME = 'index_labels_on_group_id_and_title_with_null_project_id'
  OLD_INDEX_NAME = 'index_labels_on_group_id_and_title'

  def up
    add_concurrent_index :labels, [:group_id, :title], where: 'project_id IS NULL', name: NEW_INDEX_NAME
    remove_concurrent_index_by_name :labels, OLD_INDEX_NAME
  end

  def down
    add_concurrent_index :labels, [:group_id, :title], where: 'project_id = NULL::integer', name: OLD_INDEX_NAME
    remove_concurrent_index_by_name :labels, NEW_INDEX_NAME
  end
end