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

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

  DOWNTIME = false
  INDEX_NAME = 'index_merge_request_diffs_by_id_partial'

  disable_ddl_transaction!

  def up
    add_concurrent_index(
      :merge_request_diffs,
      :id,
      name: INDEX_NAME,
      where: 'files_count > 0 AND ((NOT stored_externally) OR (stored_externally IS NULL))'
    )
  end

  def down
    remove_concurrent_index_by_name(:merge_request_diffs, INDEX_NAME)
  end
end