Commit 0ecf8e84 authored by Anne Lim's avatar Anne Lim Committed by Commit Bot

[Autofill] Add instrument_id column to Autofill Table

Please see bug for design doc.

Bug: 1121806
Change-Id: I2b847d3720f4b4c5fc2c9d7db4195c1df5367c72
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2390970Reviewed-by: default avatarJared Saul <jsaul@google.com>
Reviewed-by: default avatarTommy Martino <tmartino@chromium.org>
Reviewed-by: default avatarCait Phillips <caitkp@chromium.org>
Commit-Queue: Anne Lim <annelim@google.com>
Cr-Commit-Position: refs/heads/master@{#805471}
parent 0f693cbc
...@@ -682,6 +682,9 @@ bool AutofillTable::MigrateToVersion(int version, ...@@ -682,6 +682,9 @@ bool AutofillTable::MigrateToVersion(int version,
case 88: case 88:
*update_compatible_version = false; *update_compatible_version = false;
return MigrateToVersion88AddNewNameColumns(); return MigrateToVersion88AddNewNameColumns();
case 89:
*update_compatible_version = false;
return MigrateToVersion89AddInstrumentIdColumnToMaskedCreditCard();
} }
return true; return true;
} }
...@@ -3066,6 +3069,17 @@ bool AutofillTable::MigrateToVersion87AddCreditCardNicknameColumn() { ...@@ -3066,6 +3069,17 @@ bool AutofillTable::MigrateToVersion87AddCreditCardNicknameColumn() {
db_->Execute("ALTER TABLE credit_cards ADD COLUMN nickname VARCHAR"); db_->Execute("ALTER TABLE credit_cards ADD COLUMN nickname VARCHAR");
} }
bool AutofillTable::
MigrateToVersion89AddInstrumentIdColumnToMaskedCreditCard() {
// Add the new instrument_id column to the masked_credit_cards table and set
// the default value to 0.
return db_->DoesColumnExist("masked_credit_cards", "instrument_id") ||
db_->Execute(
"ALTER TABLE masked_credit_cards "
"ADD COLUMN instrument_id INTEGER "
"DEFAULT 0");
}
bool AutofillTable::AddFormFieldValuesTime( bool AutofillTable::AddFormFieldValuesTime(
const std::vector<FormFieldData>& elements, const std::vector<FormFieldData>& elements,
std::vector<AutofillChange>* changes, std::vector<AutofillChange>* changes,
...@@ -3466,7 +3480,8 @@ bool AutofillTable::InitMaskedCreditCardsTable() { ...@@ -3466,7 +3480,8 @@ bool AutofillTable::InitMaskedCreditCardsTable() {
"exp_year INTEGER DEFAULT 0, " "exp_year INTEGER DEFAULT 0, "
"bank_name VARCHAR, " "bank_name VARCHAR, "
"nickname VARCHAR, " "nickname VARCHAR, "
"card_issuer INTEGER DEFAULT 0)")) { "card_issuer INTEGER DEFAULT 0, "
"instrument_id INTEGER DEFAULT 0)")) {
NOTREACHED(); NOTREACHED();
return false; return false;
} }
......
...@@ -221,7 +221,8 @@ struct PaymentsCustomerData; ...@@ -221,7 +221,8 @@ struct PaymentsCustomerData;
// will additionally be added in unmasked_credit_cards. // will additionally be added in unmasked_credit_cards.
// //
// id String assigned by the server to identify this card. // id String assigned by the server to identify this card.
// This is opaque to the client. // This is a legacy version of instrument_id and is opaque
// to the client.
// status Server's status of this card. // status Server's status of this card.
// TODO(brettw) define constants for this. // TODO(brettw) define constants for this.
// name_on_card // name_on_card
...@@ -236,6 +237,9 @@ struct PaymentsCustomerData; ...@@ -236,6 +237,9 @@ struct PaymentsCustomerData;
// card_issuer Issuer for the card. An integer representing the // card_issuer Issuer for the card. An integer representing the
// CardIssuer.Issuer enum from the Chrome Sync response. // CardIssuer.Issuer enum from the Chrome Sync response.
// For example, GOOGLE or ISSUER_UNKNOWN. // For example, GOOGLE or ISSUER_UNKNOWN.
// instrument_id Credit card id assigned by the server to identify this
// card. This is opaque to the client, and |id| is the
// legacy version of this.
// //
// unmasked_credit_cards // unmasked_credit_cards
// When a masked credit credit card is unmasked and the // When a masked credit credit card is unmasked and the
...@@ -614,6 +618,7 @@ class AutofillTable : public WebDatabaseTable, ...@@ -614,6 +618,7 @@ class AutofillTable : public WebDatabaseTable,
bool MigrateToVersion86RemoveUnmaskedCreditCardsUseColumns(); bool MigrateToVersion86RemoveUnmaskedCreditCardsUseColumns();
bool MigrateToVersion87AddCreditCardNicknameColumn(); bool MigrateToVersion87AddCreditCardNicknameColumn();
bool MigrateToVersion88AddNewNameColumns(); bool MigrateToVersion88AddNewNameColumns();
bool MigrateToVersion89AddInstrumentIdColumnToMaskedCreditCard();
// Max data length saved in the table, AKA the maximum length allowed for // Max data length saved in the table, AKA the maximum length allowed for
// form data. // form data.
......
PRAGMA foreign_keys=OFF;
BEGIN TRANSACTION;
CREATE TABLE meta(key LONGVARCHAR NOT NULL UNIQUE PRIMARY KEY, value LONGVARCHAR);
INSERT INTO meta VALUES('mmap_status','-1');
INSERT INTO meta VALUES('version','88');
INSERT INTO meta VALUES('last_compatible_version','83');
INSERT INTO meta VALUES('Builtin Keyword Version','117');
CREATE TABLE token_service (service VARCHAR PRIMARY KEY NOT NULL,encrypted_token BLOB);
CREATE TABLE keywords (id INTEGER PRIMARY KEY,short_name VARCHAR NOT NULL,keyword VARCHAR NOT NULL,favicon_url VARCHAR NOT NULL,url VARCHAR NOT NULL,safe_for_autoreplace INTEGER,originating_url VARCHAR,date_created INTEGER DEFAULT 0,usage_count INTEGER DEFAULT 0,input_encodings VARCHAR,suggest_url VARCHAR,prepopulate_id INTEGER DEFAULT 0,created_by_policy INTEGER DEFAULT 0,last_modified INTEGER DEFAULT 0,sync_guid VARCHAR,alternate_urls VARCHAR,image_url VARCHAR,search_url_post_params VARCHAR,suggest_url_post_params VARCHAR,image_url_post_params VARCHAR,new_tab_url VARCHAR,last_visited INTEGER DEFAULT 0, created_from_play_api INTEGER DEFAULT 0);
CREATE TABLE autofill (name VARCHAR, value VARCHAR, value_lower VARCHAR, date_created INTEGER DEFAULT 0, date_last_used INTEGER DEFAULT 0, count INTEGER DEFAULT 1, PRIMARY KEY (name, value));
CREATE TABLE credit_cards ( guid VARCHAR PRIMARY KEY, name_on_card VARCHAR, expiration_month INTEGER, expiration_year INTEGER, card_number_encrypted BLOB, date_modified INTEGER NOT NULL DEFAULT 0, origin VARCHAR DEFAULT '', use_count INTEGER NOT NULL DEFAULT 0, use_date INTEGER NOT NULL DEFAULT 0, billing_address_id VARCHAR, nickname VARCHAR);
CREATE TABLE autofill_profiles ( guid VARCHAR PRIMARY KEY, company_name VARCHAR, street_address VARCHAR, dependent_locality VARCHAR, city VARCHAR, state VARCHAR, zipcode VARCHAR, sorting_code VARCHAR, country_code VARCHAR, date_modified INTEGER NOT NULL DEFAULT 0, origin VARCHAR DEFAULT '', language_code VARCHAR, use_count INTEGER NOT NULL DEFAULT 0, use_date INTEGER NOT NULL DEFAULT 0, validity_bitfield UNSIGNED NOT NULL DEFAULT 0, is_client_validity_states_updated BOOL NOT NULL DEFAULT FALSE);
CREATE TABLE autofill_profile_names ( guid VARCHAR, first_name VARCHAR, middle_name VARCHAR, last_name VARCHAR, full_name VARCHAR, honorific_prefix VARCHAR, first_last_name VARCHAR, conjunction_last_name VARCHAR, second_last_name VARCHAR, honorific_prefix_status INTEGER DEFAULT 0, first_name_status INTEGER DEFAULT 0, middle_name_status INTEGER DEFAULT 0, last_name_status INTEGER DEFAULT 0, first_last_name_status INTEGER DEFAULT 0, conjunction_last_name_status INTEGER DEFAULT 0, second_last_name_status INTEGER DEFAULT 0, full_name_status INTEGER DEFAULT 0);
INSERT INTO "autofill_profile_names" VALUES('B41FE6E0-B13E-2A2A-BF0B-29FCE2C3ADBD','Jon','','Smith', 'Jon Smith', 'Sir', 'Smith', 'Notsmith', 'Moresmith', 0, 0, 0, 0, 0, 0, 0, 0);
CREATE TABLE autofill_profile_emails ( guid VARCHAR, email VARCHAR);
CREATE TABLE autofill_profile_phones ( guid VARCHAR, number VARCHAR);
CREATE TABLE autofill_profiles_trash ( guid VARCHAR);
CREATE TABLE masked_credit_cards (id VARCHAR,status VARCHAR,name_on_card VARCHAR,network VARCHAR,last_four VARCHAR,exp_month INTEGER DEFAULT 0,exp_year INTEGER DEFAULT 0, bank_name VARCHAR, nickname VARCHAR, card_issuer INTEGER DEFAULT 0);
CREATE TABLE unmasked_credit_cards (id VARCHAR,card_number_encrypted VARCHAR,unmask_date INTEGER NOT NULL DEFAULT 0);
CREATE TABLE server_card_metadata (id VARCHAR NOT NULL,use_count INTEGER NOT NULL DEFAULT 0, use_date INTEGER NOT NULL DEFAULT 0, billing_address_id VARCHAR);
CREATE TABLE server_addresses (id VARCHAR,company_name VARCHAR,street_address VARCHAR,address_1 VARCHAR,address_2 VARCHAR,address_3 VARCHAR,address_4 VARCHAR,postal_code VARCHAR,sorting_code VARCHAR,country_code VARCHAR,language_code VARCHAR, recipient_name VARCHAR, phone_number VARCHAR);
CREATE TABLE server_address_metadata (id VARCHAR NOT NULL,use_count INTEGER NOT NULL DEFAULT 0, use_date INTEGER NOT NULL DEFAULT 0, has_converted BOOL NOT NULL DEFAULT FALSE);
CREATE TABLE autofill_sync_metadata (model_type INTEGER NOT NULL, storage_key VARCHAR NOT NULL, value BLOB, PRIMARY KEY (model_type, storage_key));
CREATE TABLE autofill_model_type_state (model_type INTEGER NOT NULL PRIMARY KEY, value BLOB);
CREATE TABLE payments_customer_data (customer_id VARCHAR);
CREATE TABLE payments_upi_vpa (vpa VARCHAR);
CREATE TABLE server_card_cloud_token_data ( id VARCHAR, suffix VARCHAR, exp_month INTEGER DEFAULT 0, exp_year INTEGER DEFAULT 0, card_art_url VARCHAR, instrument_token VARCHAR);
CREATE INDEX autofill_name ON autofill (name);
CREATE INDEX autofill_name_value_lower ON autofill (name, value_lower);
COMMIT;
\ No newline at end of file
...@@ -75,6 +75,7 @@ bundle_data("unit_tests_bundle_data") { ...@@ -75,6 +75,7 @@ bundle_data("unit_tests_bundle_data") {
"//components/test/data/web_database/version_85.sql", "//components/test/data/web_database/version_85.sql",
"//components/test/data/web_database/version_86.sql", "//components/test/data/web_database/version_86.sql",
"//components/test/data/web_database/version_87.sql", "//components/test/data/web_database/version_87.sql",
"//components/test/data/web_database/version_88.sql",
] ]
outputs = [ "{{bundle_resources_dir}}/" + outputs = [ "{{bundle_resources_dir}}/" +
"{{source_root_relative_dir}}/{{source_file_part}}" ] "{{source_root_relative_dir}}/{{source_file_part}}" ]
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
// corresponding changes must happen in the unit tests, and new migration test // corresponding changes must happen in the unit tests, and new migration test
// added. See |WebDatabaseMigrationTest::kCurrentTestedVersionNumber|. // added. See |WebDatabaseMigrationTest::kCurrentTestedVersionNumber|.
// static // static
const int WebDatabase::kCurrentVersionNumber = 88; const int WebDatabase::kCurrentVersionNumber = 89;
const int WebDatabase::kDeprecatedVersionNumber = 51; const int WebDatabase::kDeprecatedVersionNumber = 51;
......
...@@ -126,7 +126,7 @@ class WebDatabaseMigrationTest : public testing::Test { ...@@ -126,7 +126,7 @@ class WebDatabaseMigrationTest : public testing::Test {
DISALLOW_COPY_AND_ASSIGN(WebDatabaseMigrationTest); DISALLOW_COPY_AND_ASSIGN(WebDatabaseMigrationTest);
}; };
const int WebDatabaseMigrationTest::kCurrentTestedVersionNumber = 88; const int WebDatabaseMigrationTest::kCurrentTestedVersionNumber = 89;
void WebDatabaseMigrationTest::LoadDatabase( void WebDatabaseMigrationTest::LoadDatabase(
const base::FilePath::StringType& file) { const base::FilePath::StringType& file) {
...@@ -2007,3 +2007,37 @@ TEST_F(WebDatabaseMigrationTest, MigrateVersion87ToCurrent) { ...@@ -2007,3 +2007,37 @@ TEST_F(WebDatabaseMigrationTest, MigrateVersion87ToCurrent) {
} }
} }
} }
// Tests addition of instrument_id column in masked_credit_cards table.
TEST_F(WebDatabaseMigrationTest, MigrateVersion88ToCurrent) {
ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_88.sql")));
// Verify pre-conditions.
{
sql::Database connection;
ASSERT_TRUE(connection.Open(GetDatabasePath()));
ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
sql::MetaTable meta_table;
ASSERT_TRUE(meta_table.Init(&connection, 88, 83));
EXPECT_FALSE(
connection.DoesColumnExist("masked_credit_cards", "instrument_id"));
}
DoMigration();
// Verify post-conditions.
{
sql::Database connection;
ASSERT_TRUE(connection.Open(GetDatabasePath()));
ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
// Check version.
EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
// The card_issuer column should exist.
EXPECT_TRUE(
connection.DoesColumnExist("masked_credit_cards", "instrument_id"));
}
}
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