summaryrefslogtreecommitdiff
path: root/db/migrate/20220630202329_add_partial_index_on_oauth_access_tokens_revoked_at_with_order.rb
blob: 03eb8c2f29d351030520e01abd01b481c8b1ab4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# frozen_string_literal: true

class AddPartialIndexOnOauthAccessTokensRevokedAtWithOrder < Gitlab::Database::Migration[2.0]
  disable_ddl_transaction!

  INDEX_NAME = 'partial_index_user_id_app_id_created_at_token_not_revoked'
  EXISTING_INDEX_NAME = 'partial_index_resource_owner_id_created_at_token_not_revoked'

  def up
    add_concurrent_index :oauth_access_tokens, [:resource_owner_id, :application_id, :created_at],
                         name: INDEX_NAME, where: 'revoked_at IS NULL'
    remove_concurrent_index :oauth_access_tokens, [:resource_owner_id, :created_at], name: EXISTING_INDEX_NAME
  end

  def down
    add_concurrent_index :oauth_access_tokens, [:resource_owner_id, :created_at],
                         name: EXISTING_INDEX_NAME, where: 'revoked_at IS NULL'
    remove_concurrent_index :oauth_access_tokens, [:resource_owner_id, :application_id, :created_at], name: INDEX_NAME
  end
end