diff options
Diffstat (limited to 'db/post_migrate/20230619005223_change_unconfirmed_created_at_index_on_users.rb')
-rw-r--r-- | db/post_migrate/20230619005223_change_unconfirmed_created_at_index_on_users.rb | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/db/post_migrate/20230619005223_change_unconfirmed_created_at_index_on_users.rb b/db/post_migrate/20230619005223_change_unconfirmed_created_at_index_on_users.rb new file mode 100644 index 00000000000..5b9b4e36512 --- /dev/null +++ b/db/post_migrate/20230619005223_change_unconfirmed_created_at_index_on_users.rb @@ -0,0 +1,24 @@ +# 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 + 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" + + 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 |