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

class ChangeIndexUsersOnPublicEmail < Gitlab::Database::Migration[1.0]
  INDEX_NAME = 'index_users_on_public_email'
  INDEX_EXCLUDING_NULL_NAME = 'index_users_on_public_email_excluding_null_and_empty'

  disable_ddl_transaction!

  def up
    index_condition = "public_email != '' AND public_email IS NOT NULL"

    add_concurrent_index :users, [:public_email], where: index_condition, name: INDEX_EXCLUDING_NULL_NAME
    remove_concurrent_index_by_name :users, INDEX_NAME
  end

  def down
    index_condition = "public_email != ''"

    add_concurrent_index :users, [:public_email], where: index_condition, name: INDEX_NAME
    remove_concurrent_index_by_name :users, INDEX_EXCLUDING_NULL_NAME
  end
end