summaryrefslogtreecommitdiff
path: root/db/migrate/20171106155656_turn_issues_due_date_index_to_partial_index.rb
blob: 08784de404365f9d56a55bc72c48a0646357ca33 (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
35
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.

class TurnIssuesDueDateIndexToPartialIndex < ActiveRecord::Migration
  include Gitlab::Database::MigrationHelpers

  # Set this constant to true if this migration requires downtime.
  DOWNTIME = false

  NEW_INDEX_NAME = 'idx_issues_on_project_id_and_due_date_and_id_and_state_partial'
  OLD_INDEX_NAME = 'index_issues_on_project_id_and_due_date_and_id_and_state'

  disable_ddl_transaction!

  def up
    add_concurrent_index(
      :issues,
      [:project_id, :due_date, :id, :state],
      where: 'due_date IS NOT NULL',
      name: NEW_INDEX_NAME
    )

    remove_concurrent_index_by_name(:issues, OLD_INDEX_NAME)
  end

  def down
    add_concurrent_index(
      :issues,
      [:project_id, :due_date, :id, :state],
      name: OLD_INDEX_NAME
    )

    remove_concurrent_index_by_name(:issues, NEW_INDEX_NAME)
  end
end