Class: Gitlab::BackgroundMigration::ConvertCreditCardValidationDataToHashes
- Inherits:
-
BatchedMigrationJob
- Object
- BatchedMigrationJob
- Gitlab::BackgroundMigration::ConvertCreditCardValidationDataToHashes
- 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 collapse
- COLUMN_NAMES =
%w[last_digits holder_name network expiration_date].freeze
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, cursor, cursor?, cursor_columns, 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
38 39 40 |
# File 'lib/gitlab/background_migration/convert_credit_card_validation_data_to_hashes.rb', line 38 def hashed_value(value) Gitlab::CryptoHelper.sha256(value) if value.present? end |
#perform ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/gitlab/background_migration/convert_credit_card_validation_data_to_hashes.rb', line 17 def perform return unless COLUMN_NAMES.all? { |column| CreditCardValidation.column_names.include?(column) } 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 |