summaryrefslogtreecommitdiff
path: root/db/migrate/20200928164807_add_index_on_vulnerabilities_state_case.rb
blob: 7bfae7377d7af8b4d93e10be0da599b353103109 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# frozen_string_literal: true

class AddIndexOnVulnerabilitiesStateCase < ActiveRecord::Migration[6.0]
  include Gitlab::Database::MigrationHelpers

  DOWNTIME = false
  INDEX_NAME = 'index_vulnerabilities_on_state_case_id'
  STATE_ORDER_ARRAY_POSITION = 'ARRAY_POSITION(ARRAY[1, 4, 3, 2]::smallint[], state)'

  disable_ddl_transaction!

  def up
    add_concurrent_index :vulnerabilities, "#{STATE_ORDER_ARRAY_POSITION}, id DESC", name: INDEX_NAME
    add_concurrent_index :vulnerabilities, "#{STATE_ORDER_ARRAY_POSITION} DESC, id DESC", name: "#{INDEX_NAME}_desc"
  end

  def down
    remove_concurrent_index_by_name :vulnerabilities, "#{INDEX_NAME}_desc"
    remove_concurrent_index_by_name :vulnerabilities, INDEX_NAME
  end
end