Class: Gitlab::BackgroundMigration::BackfillAdminModeScopeForPersonalAccessTokens

Inherits:
BatchedMigrationJob
  • Object
show all
Defined in:
lib/gitlab/background_migration/backfill_admin_mode_scope_for_personal_access_tokens.rb

Overview

Backfill ‘admin_mode` scope for a range of personal access tokens

Constant Summary collapse

ADMIN_MODE_SCOPE =
['admin_mode'].freeze

Constants inherited from BatchedMigrationJob

Gitlab::BackgroundMigration::BatchedMigrationJob::DEFAULT_FEATURE_CATEGORY

Constants included from Database::DynamicModelHelpers

Database::DynamicModelHelpers::BATCH_SIZE

Instance Method Summary collapse

Methods inherited from BatchedMigrationJob

#batch_metrics, feature_category, #filter_batch, generic_instance, #initialize, job_arguments, job_arguments_count, operation_name, scope_to

Methods included from Database::DynamicModelHelpers

#define_batchable_model, #each_batch, #each_batch_range

Constructor Details

This class inherits a constructor from Gitlab::BackgroundMigration::BatchedMigrationJob

Instance Method Details

#performObject



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/gitlab/background_migration/backfill_admin_mode_scope_for_personal_access_tokens.rb', line 19

def perform
  each_sub_batch do |sub_batch|
    sub_batch.each do |token|
      existing_scopes = YAML.safe_load(token.scopes, permitted_classes: [Symbol])
      # making sure scopes are not mixed symbols and strings
      stringified_scopes = existing_scopes.map(&:to_s)

      token.update!(scopes: (stringified_scopes + ADMIN_MODE_SCOPE).uniq.to_yaml)
    end
  end
end