summaryrefslogtreecommitdiff
path: root/db/migrate/20191118182722_add_index_to_environments_on_project_id_state_environment_type.rb
blob: 01272dfad44fb247f673acc0affa059761099cab (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 AddIndexToEnvironmentsOnProjectIdStateEnvironmentType < ActiveRecord::Migration[5.2]
  include Gitlab::Database::MigrationHelpers

  DOWNTIME = false
  OLD_INDEX_NAME = 'index_environments_on_project_id_and_state'
  NEW_INDEX_NAME = 'index_environments_on_project_id_state_environment_type'

  disable_ddl_transaction!

  def up
    add_concurrent_index(:environments, [:project_id, :state, :environment_type], name: NEW_INDEX_NAME)
    remove_concurrent_index_by_name(:environments, OLD_INDEX_NAME)
  end

  def down
    add_concurrent_index(:environments, [:project_id, :state], name: OLD_INDEX_NAME)
    remove_concurrent_index_by_name(:environments, NEW_INDEX_NAME)
  end
end