Class: Gitlab::BackgroundMigration::ConvertCreditCardValidationDataToHashes

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

Overview

Converts a credit card’s expiration_date, last_digits, network & holder_name to hash and store values in new columns

Defined Under Namespace

Classes: CreditCardValidation

Constant Summary

Constants inherited from BatchedMigrationJob

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

#hashed_value(value) ⇒ Object



34
35
36
# File 'lib/gitlab/background_migration/convert_credit_card_validation_data_to_hashes.rb', line 34

def hashed_value(value)
  Gitlab::CryptoHelper.sha256(value) if value.present?
end

#performObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/gitlab/background_migration/convert_credit_card_validation_data_to_hashes.rb', line 15

def perform
  each_sub_batch do |sub_batch|
    credit_cards = CreditCardValidation.where(user_id: sub_batch)

    credit_card_hashes = credit_cards.map do |c|
      {
        user_id: c.user_id,
        credit_card_validated_at: c.credit_card_validated_at,
        last_digits_hash: hashed_value(c.last_digits),
        holder_name_hash: hashed_value(c.holder_name&.downcase),
        network_hash: hashed_value(c.network&.downcase),
        expiration_date_hash: hashed_value(c.expiration_date&.to_s)
      }
    end

    CreditCardValidation.upsert_all(credit_card_hashes)
  end
end