summaryrefslogtreecommitdiff
path: root/db/migrate/20190902131045_replace_indexes_for_counting_active_users.rb
blob: 2c7c47bee96fbea42bf9cc9af86173ffe6bfa068 (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 ReplaceIndexesForCountingActiveUsers < ActiveRecord::Migration[5.2]
  include Gitlab::Database::MigrationHelpers

  DOWNTIME = false

  disable_ddl_transaction!

  def up
    remove_concurrent_index_by_name(:users, 'index_users_on_state_and_internal')

    add_concurrent_index(:users, :state, where: 'ghost IS NOT TRUE', name: 'index_users_on_state_and_internal')
    add_concurrent_index(:users, :state, where: 'ghost IS NOT TRUE AND bot_type IS NULL', name: 'index_users_on_state_and_internal_ee')
  end

  def down
    remove_concurrent_index_by_name(:users, 'index_users_on_state_and_internal_ee')
    remove_concurrent_index_by_name(:users, 'index_users_on_state_and_internal')

    add_concurrent_index(:users, :state, where: 'ghost <> true AND bot_type IS NULL', name: 'index_users_on_state_and_internal')
  end
end