Commit 0d08d597 authored by Mark Chao's avatar Mark Chao

Add meta data in user_credit_card_validations

These are non-sensitive data according to PCI

Changelog: added
parent 812d5b02
......@@ -7,5 +7,10 @@ module Users
self.table_name = 'user_credit_card_validations'
belongs_to :user
validates :holder_name, length: { maximum: 26 }
validates :last_digits, allow_nil: true, numericality: {
greater_than_or_equal_to: 0, less_than_or_equal_to: 9999
}
end
end
# frozen_string_literal: true
class AddMetaDataToUserCreditCardValidations < Gitlab::Database::Migration[1.0]
# rubocop:disable Migration/AddLimitToTextColumns
def change
change_table :user_credit_card_validations do |t|
t.date :expiration_date
t.integer :last_digits, limit: 2 # last 4 digits
t.text :holder_name
end
end
# rubocop:enable Migration/AddLimitToTextColumns
end
# frozen_string_literal: true
class LimitHolderNameOnUserCreditCardValidations < Gitlab::Database::Migration[1.0]
disable_ddl_transaction!
def up
add_text_limit :user_credit_card_validations, :holder_name, 26 # ISO IEC 7813
add_check_constraint(:user_credit_card_validations, 'last_digits BETWEEN 0 AND 9999', constraint_name)
end
def down
remove_text_limit :user_credit_card_validations, :holder_name
remove_check_constraint(:user_credit_card_validations, constraint_name)
end
private
def constraint_name
check_constraint_name(:user_credit_card_validations, :last_digits, 'range')
end
end
# frozen_string_literal: true
class IndexMetaDataOnUserCreditCardValidations < Gitlab::Database::Migration[1.0]
disable_ddl_transaction!
INDEX_NAME = 'index_user_credit_card_validations_meta_data_full_match'
def up
add_concurrent_index :user_credit_card_validations,
[:holder_name, :expiration_date, :last_digits, :credit_card_validated_at],
name: INDEX_NAME
end
def down
remove_concurrent_index :user_credit_card_validations,
[:holder_name, :expiration_date, :last_digits, :credit_card_validated_at],
name: INDEX_NAME
end
end
7b08303dae62fe9b9b5081221a6aa4bd6b687e0206e78e4b8a6f5964bc42b344
\ No newline at end of file
52785c2791be5c17517335496e7cabd99fba1a82e82d8c783703bd68f8b40163
\ No newline at end of file
f253f2bd5643f8cf72f020e5ba5237506833dee84aa98828166d8ad1570f925f
\ No newline at end of file
......@@ -19734,7 +19734,12 @@ ALTER SEQUENCE user_canonical_emails_id_seq OWNED BY user_canonical_emails.id;
CREATE TABLE user_credit_card_validations (
user_id bigint NOT NULL,
credit_card_validated_at timestamp with time zone NOT NULL
credit_card_validated_at timestamp with time zone NOT NULL,
expiration_date date,
last_digits smallint,
holder_name text,
CONSTRAINT check_3eea080c91 CHECK (((last_digits >= 0) AND (last_digits <= 9999))),
CONSTRAINT check_eafe45d88b CHECK ((char_length(holder_name) <= 26))
);
CREATE TABLE user_custom_attributes (
......@@ -26631,6 +26636,8 @@ CREATE UNIQUE INDEX index_user_canonical_emails_on_user_id ON user_canonical_ema
CREATE UNIQUE INDEX index_user_canonical_emails_on_user_id_and_canonical_email ON user_canonical_emails USING btree (user_id, canonical_email);
CREATE INDEX index_user_credit_card_validations_meta_data_full_match ON user_credit_card_validations USING btree (holder_name, expiration_date, last_digits, credit_card_validated_at);
CREATE INDEX index_user_custom_attributes_on_key_and_value ON user_custom_attributes USING btree (key, value);
CREATE UNIQUE INDEX index_user_custom_attributes_on_user_id_and_key ON user_custom_attributes USING btree (user_id, key);
......@@ -4,5 +4,8 @@ FactoryBot.modify do
factory :credit_card_validation do
user
credit_card_validated_at { Time.current }
expiration_date { 1.year.from_now.end_of_month }
last_digits { 10 }
holder_name { 'John Smith' }
end
end
......@@ -4,4 +4,7 @@ require 'spec_helper'
RSpec.describe Users::CreditCardValidation do
it { is_expected.to belong_to(:user) }
it { is_expected.to validate_length_of(:holder_name).is_at_most(26) }
it { is_expected.to validate_numericality_of(:last_digits).is_less_than_or_equal_to(9999) }
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment