diff options
author | michaelbai@google.com <michaelbai@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-19 17:39:20 +0000 |
---|---|---|
committer | michaelbai@google.com <michaelbai@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-19 17:39:20 +0000 |
commit | b124d4e0781da0c6cfc648e64ee4d4fbf90e6186 (patch) | |
tree | da31d406a39da1c7efdedd61943c95fd6aa0c3d7 /chrome/browser/history | |
parent | 5ba26b0befcfbac872cc914314fd6a611e023b29 (diff) | |
download | chromium_src-b124d4e0781da0c6cfc648e64ee4d4fbf90e6186.zip chromium_src-b124d4e0781da0c6cfc648e64ee4d4fbf90e6186.tar.gz chromium_src-b124d4e0781da0c6cfc648e64ee4d4fbf90e6186.tar.bz2 |
Upgrade the history database to version 23
- Android_urls table data schema was changed.
- Migrate the data to new table.
BUG=
TEST=
Review URL: https://chromiumcodereview.appspot.com/10067030
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@133008 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/history')
4 files changed, 102 insertions, 1 deletions
diff --git a/chrome/browser/history/android/android_urls_database.cc b/chrome/browser/history/android/android_urls_database.cc index 1527b6a..b76703a 100644 --- a/chrome/browser/history/android/android_urls_database.cc +++ b/chrome/browser/history/android/android_urls_database.cc @@ -144,4 +144,25 @@ bool AndroidURLsDatabase::ClearAndroidURLRows() { return GetDB().Execute("DELETE FROM android_urls"); } +bool AndroidURLsDatabase::MigrateToVersion22() { + if (!GetDB().DoesTableExist("android_urls")) + return true; + + if (!GetDB().Execute("ALTER TABLE android_urls RENAME TO android_urls_tmp")) + return false; + + if (!CreateAndroidURLsTable()) + return false; + + if (!GetDB().Execute( + "INSERT INTO android_urls (id, raw_url, url_id) " + "SELECT id, raw_url, url_id FROM android_urls_tmp")) + return false; + + if (!GetDB().Execute("DROP TABLE android_urls_tmp")) + return false; + + return true; +} + } // namespace history diff --git a/chrome/browser/history/android/android_urls_database.h b/chrome/browser/history/android/android_urls_database.h index 0065fcc..fda6354 100644 --- a/chrome/browser/history/android/android_urls_database.h +++ b/chrome/browser/history/android/android_urls_database.h @@ -56,6 +56,9 @@ class AndroidURLsDatabase { // on error. bool ClearAndroidURLRows(); + // Migrate from version 21 to 22. + bool MigrateToVersion22(); + protected: // Returns the database for the functions in this interface. The decendent of // this class implements these functions to return its objects. diff --git a/chrome/browser/history/android/android_urls_database_unittest.cc b/chrome/browser/history/android/android_urls_database_unittest.cc new file mode 100644 index 0000000..8650c55 --- /dev/null +++ b/chrome/browser/history/android/android_urls_database_unittest.cc @@ -0,0 +1,67 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/history/android/android_urls_database.h" + +#include "base/file_path.h" +#include "base/file_util.h" +#include "base/path_service.h" +#include "base/scoped_temp_dir.h" +#include "chrome/browser/history/history_database.h" +#include "chrome/browser/history/history_unittest_base.h" +#include "chrome/common/chrome_constants.h" +#include "chrome/common/chrome_paths.h" +#include "chrome/test/base/testing_profile.h" + +namespace history { + +class AndroidURLsMigrationTest : public HistoryUnitTestBase { + public: + AndroidURLsMigrationTest() { + } + ~AndroidURLsMigrationTest() { + } + + protected: + virtual void SetUp() { + profile_.reset(new TestingProfile); + + FilePath data_path; + ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path)); + data_path = data_path.AppendASCII("History"); + + history_db_name_ = profile_->GetPath().Append(chrome::kHistoryFilename); + // Set up history as they would be before migration. + ASSERT_NO_FATAL_FAILURE( + ExecuteSQLScript(data_path.AppendASCII("history.21.sql"), + history_db_name_)); + } + + protected: + FilePath history_db_name_; + scoped_ptr<TestingProfile> profile_; +}; + +TEST_F(AndroidURLsMigrationTest, MigrateToVersion22) { + HistoryDatabase db; + ASSERT_EQ(sql::INIT_OK, db.Init(history_db_name_, profile_->GetPath())); + // Migration has done. + // The column of previous table shouldn't exist. + EXPECT_FALSE(db.GetDB().DoesColumnExist("android_urls", "bookmark")); + sql::Statement statement(db.GetDB().GetUniqueStatement( + "SELECT id, url_id, raw_url FROM android_urls ORDER BY id ASC")); + ASSERT_TRUE(statement.Step()); + EXPECT_EQ(1, statement.ColumnInt64(0)); + EXPECT_EQ("http://google.com/", statement.ColumnString(2)); + EXPECT_EQ(1, statement.ColumnInt64(1)); + + ASSERT_TRUE(statement.Step()); + EXPECT_EQ(4, statement.ColumnInt64(0)); + EXPECT_EQ("www.google.com/", statement.ColumnString(2)); + EXPECT_EQ(3, statement.ColumnInt64(1)); + + EXPECT_FALSE(statement.Step()); +} + +} // namespace history diff --git a/chrome/browser/history/history_database.cc b/chrome/browser/history/history_database.cc index f4c3aa1..0e65f95 100644 --- a/chrome/browser/history/history_database.cc +++ b/chrome/browser/history/history_database.cc @@ -28,7 +28,7 @@ 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 // or database without *too* many bad effects. -static const int kCurrentVersionNumber = 21; +static const int kCurrentVersionNumber = 22; static const int kCompatibleVersionNumber = 16; static const char kEarlyExpirationThresholdKey[] = "early_expiration_threshold"; @@ -322,6 +322,16 @@ sql::InitStatus HistoryDatabase::EnsureCurrentVersion( meta_table_.SetVersionNumber(cur_version); } + if (cur_version == 21) { + // The android_urls table's data schemal was changed in version 21. +#if defined(OS_ANDROID) + if (!MigrateToVersion22()) { + LOG(WARNING) << "Unable to migrate the android_urls table to version 22"; + } +#endif + ++cur_version; + meta_table_.SetVersionNumber(cur_version); + } // When the version is too old, we just try to continue anyway, there should // not be a released product that makes a database too old for us to handle. LOG_IF(WARNING, cur_version < GetCurrentVersion()) << |