summaryrefslogtreecommitdiff
path: root/db/migrate/20191204093410_add_label_project_group_partial_indexes.rb
blob: 85666144856fd20477ba9390289d02cc0a1453f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# frozen_string_literal: true

# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.

class AddLabelProjectGroupPartialIndexes < ActiveRecord::Migration[5.2]
  include Gitlab::Database::MigrationHelpers

  DOWNTIME = false

  disable_ddl_transaction!

  PROJECT_AND_TITLE = [:project_id, :title]
  GROUP_AND_TITLE = [:group_id, :title]

  def up
    add_concurrent_index :labels, PROJECT_AND_TITLE, unique: false, where: "labels.group_id = null"
    add_concurrent_index :labels, GROUP_AND_TITLE, unique: false, where: "labels.project_id = null"
  end

  def down
    remove_concurrent_index :labels, PROJECT_AND_TITLE
    remove_concurrent_index :labels, GROUP_AND_TITLE
  end
end