blob: 7bb3b661caadc21dd1d2f78b9b57c06a10b6e50f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# frozen_string_literal: true
module Gitlab
module BackgroundMigration
# Converts a credit card's expiration_date, last_digits, network & holder_name
# to hash and store values in new columns
class ConvertCreditCardValidationDataToHashes < BatchedMigrationJob
operation_name :convert_credit_card_data
feature_category :user_profile
class CreditCardValidation < ApplicationRecord # rubocop:disable Style/Documentation
self.table_name = 'user_credit_card_validations'
end
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
def hashed_value(value)
Gitlab::CryptoHelper.sha256(value) if value.present?
end
end
end
end
|