Commit ef68c87c authored by skanuj@chromium.org's avatar skanuj@chromium.org

Migrate old Shortcuts DB data to conform to new type values

All new suggestion types will be a Google Search URL with https. In some cases,
url may contain additional identifying parameter.

BUG=339270
TBR=brettw@chromium.org

Review URL: https://codereview.chromium.org/134853004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@251442 0039d316-1c4b-4281-b951-d872f2087c98
parent 6eb45f5b
...@@ -26,7 +26,7 @@ namespace { ...@@ -26,7 +26,7 @@ namespace {
// Current version number. We write databases at the "current" version number, // Current version number. We write databases at the "current" version number,
// but any previous version that can read the "compatible" one can make do with // but any previous version that can read the "compatible" one can make do with
// or database without *too* many bad effects. // our database without *too* many bad effects.
const int kCurrentVersionNumber = 28; const int kCurrentVersionNumber = 28;
const int kCompatibleVersionNumber = 16; const int kCompatibleVersionNumber = 16;
const char kEarlyExpirationThresholdKey[] = "early_expiration_threshold"; const char kEarlyExpirationThresholdKey[] = "early_expiration_threshold";
......
...@@ -11,11 +11,18 @@ ...@@ -11,11 +11,18 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "sql/meta_table.h"
#include "sql/statement.h" #include "sql/statement.h"
#include "sql/transaction.h" #include "sql/transaction.h"
namespace { namespace {
// Current version number. We write databases at the "current" version number,
// but any previous version that can read the "compatible" one can make do with
// our database without *too* many bad effects.
const int kCurrentVersionNumber = 1;
const int kCompatibleVersionNumber = 1;
void BindShortcutToStatement( void BindShortcutToStatement(
const history::ShortcutsBackend::Shortcut& shortcut, const history::ShortcutsBackend::Shortcut& shortcut,
sql::Statement* s) { sql::Statement* s) {
...@@ -177,8 +184,7 @@ bool ShortcutsDatabase::EnsureTable() { ...@@ -177,8 +184,7 @@ bool ShortcutsDatabase::EnsureTable() {
// Perform the upgrade in a transaction to ensure it doesn't happen // Perform the upgrade in a transaction to ensure it doesn't happen
// incompletely. // incompletely.
sql::Transaction transaction(&db_); sql::Transaction transaction(&db_);
transaction.Begin(); if (!(transaction.Begin() &&
return
db_.Execute("ALTER TABLE omni_box_shortcuts " db_.Execute("ALTER TABLE omni_box_shortcuts "
"ADD COLUMN fill_into_edit VARCHAR") && "ADD COLUMN fill_into_edit VARCHAR") &&
db_.Execute("UPDATE omni_box_shortcuts SET fill_into_edit = url") && db_.Execute("UPDATE omni_box_shortcuts SET fill_into_edit = url") &&
...@@ -193,9 +199,31 @@ bool ShortcutsDatabase::EnsureTable() { ...@@ -193,9 +199,31 @@ bool ShortcutsDatabase::EnsureTable() {
static_cast<int>(AutocompleteMatchType::HISTORY_TITLE)).c_str()) && static_cast<int>(AutocompleteMatchType::HISTORY_TITLE)).c_str()) &&
db_.Execute("ALTER TABLE omni_box_shortcuts " db_.Execute("ALTER TABLE omni_box_shortcuts "
"ADD COLUMN keyword VARCHAR") && "ADD COLUMN keyword VARCHAR") &&
transaction.Commit(); transaction.Commit())) {
return false;
}
} }
if (!sql::MetaTable::DoesTableExist(&db_)) {
meta_table_.Init(&db_, kCurrentVersionNumber, kCompatibleVersionNumber);
sql::Transaction transaction(&db_);
if (!(transaction.Begin() &&
// Migrate old SEARCH_OTHER_ENGINE values to the new type value.
db_.Execute(base::StringPrintf("UPDATE omni_box_shortcuts "
"SET type = 13 WHERE type = 9").c_str()) &&
// Migrate old EXTENSION_APP values to the new type value.
db_.Execute(base::StringPrintf("UPDATE omni_box_shortcuts "
"SET type = 14 WHERE type = 10").c_str()) &&
// Migrate old CONTACT values to the new type value.
db_.Execute(base::StringPrintf("UPDATE omni_box_shortcuts "
"SET type = 15 WHERE type = 11").c_str()) &&
// Migrate old BOOKMARK_TITLE values to the new type value.
db_.Execute(base::StringPrintf("UPDATE omni_box_shortcuts "
"SET type = 16 WHERE type = 12").c_str()) &&
transaction.Commit())) {
return false;
}
}
return true; return true;
} }
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "chrome/browser/history/shortcuts_backend.h" #include "chrome/browser/history/shortcuts_backend.h"
#include "sql/connection.h" #include "sql/connection.h"
#include "sql/meta_table.h"
#include "url/gurl.h" #include "url/gurl.h"
namespace history { namespace history {
...@@ -81,6 +82,8 @@ class ShortcutsDatabase : public base::RefCountedThreadSafe<ShortcutsDatabase> { ...@@ -81,6 +82,8 @@ class ShortcutsDatabase : public base::RefCountedThreadSafe<ShortcutsDatabase> {
sql::Connection db_; sql::Connection db_;
base::FilePath database_path_; base::FilePath database_path_;
sql::MetaTable meta_table_;
static const base::FilePath::CharType kShortcutsDatabaseName[]; static const base::FilePath::CharType kShortcutsDatabaseName[];
DISALLOW_COPY_AND_ASSIGN(ShortcutsDatabase); DISALLOW_COPY_AND_ASSIGN(ShortcutsDatabase);
......
...@@ -257,11 +257,11 @@ TEST_F(ShortcutsDatabaseTest, DeleteAllShortcuts) { ...@@ -257,11 +257,11 @@ TEST_F(ShortcutsDatabaseTest, DeleteAllShortcuts) {
EXPECT_EQ(0U, shortcuts.size()); EXPECT_EQ(0U, shortcuts.size());
} }
TEST(ShortcutsDatabaseMigrationTest, MigrateV1ToV2) { TEST(ShortcutsDatabaseMigrationTest, MigrateTableAddFillIntoEdit) {
// Open the v1 test file and use it to create a test database in a temp dir. // Open the v0 test file and use it to create a test database in a temp dir.
base::FilePath sql_path; base::FilePath sql_path;
ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &sql_path)); ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &sql_path));
sql_path = sql_path.AppendASCII("History").AppendASCII("Shortcuts.v1.sql"); sql_path = sql_path.AppendASCII("History").AppendASCII("Shortcuts.v0.sql");
base::ScopedTempDir temp_dir; base::ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
base::FilePath db_path(temp_dir.path().AppendASCII("TestShortcuts.db")); base::FilePath db_path(temp_dir.path().AppendASCII("TestShortcuts.db"));
...@@ -299,4 +299,32 @@ TEST(ShortcutsDatabaseMigrationTest, MigrateV1ToV2) { ...@@ -299,4 +299,32 @@ TEST(ShortcutsDatabaseMigrationTest, MigrateV1ToV2) {
EXPECT_TRUE(statement.Succeeded()); EXPECT_TRUE(statement.Succeeded());
} }
TEST(ShortcutsDatabaseMigrationTest, MigrateV0ToV1) {
// Open the v1 test file and use it to create a test database in a temp dir.
base::FilePath sql_path;
ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &sql_path));
sql_path = sql_path.AppendASCII("History").AppendASCII("Shortcuts.v1.sql");
base::ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
base::FilePath db_path(temp_dir.path().AppendASCII("TestShortcuts.db"));
ASSERT_TRUE(sql::test::CreateDatabaseFromSQL(db_path, sql_path));
// Create a ShortcutsDatabase from the test database, which will migrate the
// test database to the current version.
{
scoped_refptr<ShortcutsDatabase> db(new ShortcutsDatabase(db_path));
db->Init();
}
// Check that all the old type values got converted to new values.
sql::Connection connection;
ASSERT_TRUE(connection.Open(db_path));
sql::Statement statement(connection.GetUniqueStatement(
"SELECT count(1) FROM omni_box_shortcuts WHERE type in (9, 10, 11, 12)"));
ASSERT_TRUE(statement.is_valid());
while (statement.Step())
EXPECT_EQ(0, statement.ColumnInt(0));
EXPECT_TRUE(statement.Succeeded());
}
} // namespace history } // namespace history
PRAGMA foreign_keys=OFF;
BEGIN TRANSACTION;
CREATE TABLE omni_box_shortcuts ( id VARCHAR PRIMARY KEY, text VARCHAR, url VARCHAR, contents VARCHAR, contents_class VARCHAR, description VARCHAR, description_class VARCHAR, last_access_time INTEGER, number_of_hits INTEGER);
INSERT INTO "omni_box_shortcuts" VALUES('34A7401D-0DC5-4A8F-A6B5-3FA4FF786C42','sha','http://shacknews.com/','shacknews.com','0,1','Video Game News and Features - Video Game News, Videos, and File Downloads for PC and Console Games at Shacknews.com','0,0',13024194201806179,3);
INSERT INTO "omni_box_shortcuts" VALUES('9EA31BB8-8528-4AE0-A6B1-FD06458DFC31','shacknews','http://shacknews.com/','shacknews.com','0,1','Video Game News and Features - Video Game News, Videos, and File Downloads for PC and Console Games at Shacknews.com','0,0',13024456716613368,4);
INSERT INTO "omni_box_shortcuts" VALUES('CD853DC4-7C4E-4E64-903D-A4BBCAA410F9','shacknews.com','http://shacknews.com/','shacknews.com','0,1','Video Game News and Features - Video Game News, Videos, and File Downloads for PC and Console Games at Shacknews.com','0,0',13024196901413541,1);
INSERT INTO "omni_box_shortcuts" VALUES('377314F7-E3AB-4264-8F3F-3404BE48DADB','echo echo','chrome-extension://cedabbhfglmiikkmdgcpjdkocfcmbkee/?q=echo','Run Echo command: echo','0,0','Echo','0,4',13025401559133998,2);
INSERT INTO "omni_box_shortcuts" VALUES('BCE200CA-01E9-4A2F-B5EC-2D561DDFBE41','echo','chrome-extension://cedabbhfglmiikkmdgcpjdkocfcmbkee/?q=frobber','Run Echo command: frobber','0,0','Echo','0,4',13025413423801769,2);
COMMIT;
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