summaryrefslogtreecommitdiff
path: root/db/migrate/20190802012622_reorder_issues_project_id_relative_position_index.rb
blob: 12088dd763f1f7cf8e04e7ca91af3ccaed090d2f (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
# frozen_string_literal: true

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

  DOWNTIME = false

  disable_ddl_transaction!

  OLD_INDEX_NAME = 'index_issues_on_project_id_and_state_and_rel_position_and_id'
  NEW_INDEX_NAME = 'index_issues_on_project_id_and_rel_position_and_state_and_id'

  def up
    add_concurrent_index :issues, [:project_id, :relative_position, :state, :id], order: { id: :desc }, name: NEW_INDEX_NAME

    remove_concurrent_index_by_name :issues, OLD_INDEX_NAME
  end

  def down
    add_concurrent_index :issues, [:project_id, :state, :relative_position, :id], order: { id: :desc }, name: OLD_INDEX_NAME

    remove_concurrent_index_by_name :issues, NEW_INDEX_NAME
  end
end