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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'db/post_migrate/20221210154044_update_active_billable_users_index.rb')
-rw-r--r--db/post_migrate/20221210154044_update_active_billable_users_index.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/db/post_migrate/20221210154044_update_active_billable_users_index.rb b/db/post_migrate/20221210154044_update_active_billable_users_index.rb
new file mode 100644
index 00000000000..9d306eff16b
--- /dev/null
+++ b/db/post_migrate/20221210154044_update_active_billable_users_index.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+class UpdateActiveBillableUsersIndex < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ OLD_INDEX_NAME = 'active_billable_users'
+ NEW_INDEX_NAME = 'index_users_for_active_billable'
+ TABLE_NAME = 'users'
+ COLUMNS = %i[id]
+ OLD_INDEX_FILTER_CONDITION = <<~QUERY
+ ((state)::text = 'active'::text) AND ((user_type IS NULL)
+ OR (user_type = ANY (ARRAY[NULL::integer, 6, 4]))) AND ((user_type IS NULL)
+ OR (user_type <> ALL ('{2,6,1,3,7,8}'::smallint[])))
+ QUERY
+ NEW_INDEX_FILTER_CONDITION = <<~QUERY
+ ((state)::text = 'active'::text) AND ((user_type IS NULL)
+ OR (user_type = ANY (ARRAY[NULL::integer, 6, 4]))) AND ((user_type IS NULL)
+ OR (user_type <> ALL ('{1,2,3,4,5,6,7,8,9,11}'::smallint[])))
+ QUERY
+
+ def up
+ add_concurrent_index(TABLE_NAME, COLUMNS, where: NEW_INDEX_FILTER_CONDITION, name: NEW_INDEX_NAME)
+ remove_concurrent_index_by_name(TABLE_NAME, OLD_INDEX_NAME)
+ end
+
+ def down
+ add_concurrent_index(TABLE_NAME, COLUMNS, where: OLD_INDEX_FILTER_CONDITION, name: OLD_INDEX_NAME)
+ remove_concurrent_index_by_name(TABLE_NAME, NEW_INDEX_NAME)
+ end
+end