Welcome to mirror list, hosted at ThFree Co, Russian Federation.

20220616092541_prepare_index_issues_on_project_id_and_closed_at.rb « post_migrate « db - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 084cdb6166d3d9ec911d9ce00898c92041bca9d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# frozen_string_literal: true

class PrepareIndexIssuesOnProjectIdAndClosedAt < Gitlab::Database::Migration[2.0]
  NEW_INDEX_NAME_1 = 'index_issues_on_project_id_closed_at_desc_state_id_and_id'
  NEW_INDEX_NAME_2 = 'index_issues_on_project_id_closed_at_state_id_and_id'

  def up
    # Index to improve performance when sorting issues by closed_at desc
    prepare_async_index :issues, 'project_id, closed_at DESC NULLS LAST, state_id, id', name: NEW_INDEX_NAME_1

    # Index to improve performance when sorting issues by closed_at asc
    # This replaces the old index which didn't account for state_id and id
    prepare_async_index :issues, [:project_id, :closed_at, :state_id, :id], name: NEW_INDEX_NAME_2
  end

  def down
    unprepare_async_index_by_name :issues, NEW_INDEX_NAME_1
    unprepare_async_index_by_name :issues, NEW_INDEX_NAME_2
  end
end