summaryrefslogtreecommitdiff
path: root/db/post_migrate/20200626060151_add_disable_overriding_approvers_per_merge_request_indices.rb
blob: 6f2db4035e29ccbe8ca6dfe5474e66f9b859e623 (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
26
# frozen_string_literal: true

class AddDisableOverridingApproversPerMergeRequestIndices < ActiveRecord::Migration[6.0]
  include Gitlab::Database::MigrationHelpers

  DOWNTIME = false
  DISABLE_OVERRIDING_APPROVERS_TRUE_INDEX_NAME = "idx_projects_id_created_at_disable_overriding_approvers_true"
  DISABLE_OVERRIDING_APPROVERS_FALSE_INDEX_NAME = "idx_projects_id_created_at_disable_overriding_approvers_false"

  disable_ddl_transaction!

  def up
    add_concurrent_index :projects, [:id, :created_at],
      where: "disable_overriding_approvers_per_merge_request = TRUE",
      name: DISABLE_OVERRIDING_APPROVERS_TRUE_INDEX_NAME

    add_concurrent_index :projects, [:id, :created_at],
      where: "(disable_overriding_approvers_per_merge_request = FALSE) OR (disable_overriding_approvers_per_merge_request IS NULL)",
      name: DISABLE_OVERRIDING_APPROVERS_FALSE_INDEX_NAME
  end

  def down
    remove_concurrent_index_by_name :projects, DISABLE_OVERRIDING_APPROVERS_TRUE_INDEX_NAME
    remove_concurrent_index_by_name :projects, DISABLE_OVERRIDING_APPROVERS_FALSE_INDEX_NAME
  end
end