summaryrefslogtreecommitdiff
path: root/db/migrate/20200721230558_add_index_to_projects_aimed_for_deletion.rb
blob: 44dfe2ff3e113f3f7003d0ec0c70b642ee609f68 (plain)
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
# frozen_string_literal: true

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

  DOWNTIME = false

  PROJECTS_AIMED_FOR_DELETION_INDEX_NAME = "index_projects_aimed_for_deletion"
  MARKED_FOR_DELETION_PROJECTS_INDEX_NAME = "index_projects_on_marked_for_deletion_at"

  disable_ddl_transaction!

  def up
    add_concurrent_index :projects,
                         :marked_for_deletion_at,
                         where: "marked_for_deletion_at IS NOT NULL AND pending_delete = false",
                         name: PROJECTS_AIMED_FOR_DELETION_INDEX_NAME

    remove_concurrent_index_by_name :projects, MARKED_FOR_DELETION_PROJECTS_INDEX_NAME
  end

  def down
    remove_concurrent_index_by_name :projects, PROJECTS_AIMED_FOR_DELETION_INDEX_NAME

    add_concurrent_index :projects, :marked_for_deletion_at, where: 'marked_for_deletion_at IS NOT NULL'
  end
end