summaryrefslogtreecommitdiff
path: root/db/migrate/20200312160532_add_index_on_mirror_and_id_to_projects.rb
blob: 3a64b9159317ed642eb536bf917f210d198e07a3 (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 AddIndexOnMirrorAndIdToProjects < ActiveRecord::Migration[6.0]
  include Gitlab::Database::MigrationHelpers

  DOWNTIME = false
  OLD_INDEX_NAME = 'index_projects_on_mirror_and_mirror_trigger_builds_both_true'
  NEW_INDEX_NAME = 'index_projects_on_mirror_id_where_mirror_and_trigger_builds'

  disable_ddl_transaction!

  def up
    add_concurrent_index :projects, :id, where: 'mirror = TRUE AND mirror_trigger_builds = TRUE', name: NEW_INDEX_NAME
    remove_concurrent_index_by_name :projects, OLD_INDEX_NAME
  end

  def down
    add_concurrent_index :projects, :id, where: 'mirror IS TRUE AND mirror_trigger_builds IS TRUE', name: OLD_INDEX_NAME
    remove_concurrent_index_by_name :projects, NEW_INDEX_NAME
  end
end