summaryrefslogtreecommitdiff
path: root/db/migrate/20190506135337_add_temporary_indexes_to_state_id.rb
blob: 8e9838e1afb8efaaa8d7db97401cec8f4d1e4182 (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
27
28
29
30
31
32
33
34
# frozen_string_literal: true

# This migration adds temporary indexes to state_id column of issues
# and merge_requests tables. It will be used only to peform the scheduling
# for populating state_id in a post migrate and will be removed after it.
# Check: ScheduleSyncIssuablesStateIdWhereNil.

class AddTemporaryIndexesToStateId < ActiveRecord::Migration[5.1]
  include Gitlab::Database::MigrationHelpers

  DOWNTIME = false

  disable_ddl_transaction!

  def up
    %w(issues merge_requests).each do |table|
      add_concurrent_index(
        table,
        'id',
        name: index_name_for(table),
        where: "state_id IS NULL"
      )
    end
  end

  def down
    remove_concurrent_index_by_name(:issues, index_name_for("issues"))
    remove_concurrent_index_by_name(:merge_requests, index_name_for("merge_requests"))
  end

  def index_name_for(table)
    "idx_on_#{table}_where_state_id_is_null"
  end
end