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

20230310111859_recreate_user_type_migration_indexes.rb « post_migrate « db - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 147409bf5f0d6d52e9273c4664fe6e7e93928c4a (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 RecreateUserTypeMigrationIndexes < Gitlab::Database::Migration[2.1]
  disable_ddl_transaction!

  INCORRECT_BILLABLE_INDEX = 'index_users_for_active_billable_users_migration'
  BILLABLE_INDEX = 'migrate_index_users_for_active_billable_users'

  def up
    # Temporary index to migrate human user_type. See https://gitlab.com/gitlab-org/gitlab/-/issues/386474
    # rubocop:disable Migration/PreventIndexCreation
    add_concurrent_index :users, :id, name: BILLABLE_INDEX,
      where: "state = 'active' AND ((user_type IS NULL OR user_type = 0) OR (user_type = ANY (ARRAY[0, 6, 4, 13]))) " \
             "AND ((user_type IS NULL OR user_type = 0) OR (user_type = ANY (ARRAY[0, 4, 5])))"
    # rubocop:enable Migration/PreventIndexCreation

    remove_concurrent_index_by_name :users, INCORRECT_BILLABLE_INDEX
  end

  def down
    add_concurrent_index :users, :id, name: INCORRECT_BILLABLE_INDEX,
      where: "state = 'active' AND ((user_type IS NULL OR user_type = 0) OR (user_type = ANY (ARRAY[6, 4, 13]))) " \
             "AND ((user_type IS NULL OR user_type = 0) OR (user_type = ANY (ARRAY[4, 5])))"
    remove_concurrent_index_by_name :users, BILLABLE_INDEX
  end
end