diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2016-03-28 17:28:35 -0700 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2016-03-28 17:28:44 -0700 |
commit | 13882a31e478466b98dd4dfb7eebbd97c0627e06 (patch) | |
tree | d4251193c1f88cacbdc433899fcbdfa57c07c16d | |
parent | 635aebbb89d205a52806ebfa18214d3a649c7291 (diff) | |
download | qtlocation-mapboxgl-13882a31e478466b98dd4dfb7eebbd97c0627e06.tar.gz |
[core] Set schema version to 3 after upgrading
The migration was upgrading the schema, but not the schema version. As a result, the (expensive) migration was running every time an OfflineDatabase was constructed with a v2 database.
Fixes #4501
-rw-r--r-- | platform/default/mbgl/storage/offline_database.cpp | 1 | ||||
-rw-r--r-- | test/storage/offline_database.cpp | 8 |
2 files changed, 9 insertions, 0 deletions
diff --git a/platform/default/mbgl/storage/offline_database.cpp b/platform/default/mbgl/storage/offline_database.cpp index 43f7abaf9d..0b8dec01bf 100644 --- a/platform/default/mbgl/storage/offline_database.cpp +++ b/platform/default/mbgl/storage/offline_database.cpp @@ -111,6 +111,7 @@ void OfflineDatabase::removeExisting() { void OfflineDatabase::migrateToVersion3() { db->exec("PRAGMA auto_vacuum = INCREMENTAL"); db->exec("VACUUM"); + db->exec("PRAGMA user_version = 3"); } OfflineDatabase::Statement OfflineDatabase::getStatement(const char * sql) { diff --git a/test/storage/offline_database.cpp b/test/storage/offline_database.cpp index 11d56c237b..65812c6e8d 100644 --- a/test/storage/offline_database.cpp +++ b/test/storage/offline_database.cpp @@ -669,6 +669,13 @@ static int databasePageCount(const std::string& path) { return stmt.get<int>(0); } +static int databaseUserVersion(const std::string& path) { + mapbox::sqlite::Database db(path, mapbox::sqlite::ReadOnly); + mapbox::sqlite::Statement stmt = db.prepare("pragma user_version"); + stmt.run(); + return stmt.get<int>(0); +} + TEST(OfflineDatabase, MigrateFromV2Schema) { using namespace mbgl; @@ -685,6 +692,7 @@ TEST(OfflineDatabase, MigrateFromV2Schema) { } } + EXPECT_EQ(3, databaseUserVersion("test/fixtures/offline/v3.db")); EXPECT_LT(databasePageCount("test/fixtures/offline/v3.db"), databasePageCount("test/fixtures/offline/v2.db")); } |