Read about our upcoming Code of Conduct on this issue

20191204070713_change_updated_at_index_and_add_index_to_id_on_deployments.rb 901 Bytes
Newer Older
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
# frozen_string_literal: true

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

  disable_ddl_transaction!

  DOWNTIME = false

  PROJECT_ID_INDEX_PARAMS = [[:project_id, :id], order: { id: :desc }]
  OLD_UPDATED_AT_INDEX_PARAMS = [[:project_id, :updated_at]]
  NEW_UPDATED_AT_INDEX_PARAMS = [[:project_id, :updated_at, :id], order: { updated_at: :desc, id: :desc }]

  def up
    add_concurrent_index :deployments, *NEW_UPDATED_AT_INDEX_PARAMS

    remove_concurrent_index :deployments, *OLD_UPDATED_AT_INDEX_PARAMS

    add_concurrent_index :deployments, *PROJECT_ID_INDEX_PARAMS
  end

  def down
    add_concurrent_index :deployments, *OLD_UPDATED_AT_INDEX_PARAMS

    remove_concurrent_index :deployments, *NEW_UPDATED_AT_INDEX_PARAMS

    remove_concurrent_index :deployments, *PROJECT_ID_INDEX_PARAMS
  end
end