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

20230303154314_add_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: d4f48c1c977e4eacb9a68e7532aea680c835d67b (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
# frozen_string_literal: true

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

  BILLABLE_INDEX = 'index_users_for_active_billable_users_migration'
  LAST_ACTIVITY_INDEX = 'i_users_on_last_activity_for_active_human_service_migration'

  # rubocop:disable Migration/PreventIndexCreation
  def up
    # Temporary indexes to migrate human user_type. See https://gitlab.com/gitlab-org/gitlab/-/issues/386474
    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[6, 4, 13]))) " \
             "AND ((user_type IS NULL OR user_type = 0) OR (user_type = ANY (ARRAY[4, 5])))"
    add_concurrent_index :users, [:id, :last_activity_on], name: LAST_ACTIVITY_INDEX,
      where: "((state)::text = 'active'::text) AND ((user_type IS NULL OR user_type = 0) OR (user_type = 4))"
  end
  # rubocop:enable Migration/PreventIndexCreation

  def down
    remove_concurrent_index_by_name :users, BILLABLE_INDEX
    remove_concurrent_index_by_name :users, LAST_ACTIVITY_INDEX
  end
end