Welcome to mirror list, hosted at ThFree Co, Russian Federation.

20230619005223_change_unconfirmed_created_at_index_on_users.rb « post_migrate « db - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e299ce394a337073ea2bbe6f01fa105a57a4c624 (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
# frozen_string_literal: true

class ChangeUnconfirmedCreatedAtIndexOnUsers < Gitlab::Database::Migration[2.1]
  disable_ddl_transaction!

  OLD_INDEX_NAME = 'index_users_on_unconfirmed_and_created_at_for_active_humans'
  NEW_INDEX_NAME = 'index_users_on_unconfirmed_created_at_active_type_sign_in_count'

  def up
    # rubocop:disable Migration/PreventIndexCreation
    add_concurrent_index :users, [:created_at, :id],
      name: NEW_INDEX_NAME,
      where: "confirmed_at IS NULL AND state = 'active' AND user_type IN (0) AND sign_in_count = 0"
    # rubocop:enable Migration/PreventIndexCreation

    remove_concurrent_index_by_name :users, OLD_INDEX_NAME
  end

  def down
    add_concurrent_index :users, [:created_at, :id],
      name: OLD_INDEX_NAME,
      where: "confirmed_at IS NULL AND state = 'active' AND user_type IN (0)"

    remove_concurrent_index_by_name :users, NEW_INDEX_NAME
  end
end