From eb72fe580b61b68cb24f9ae57b210857a430bfdc Mon Sep 17 00:00:00 2001 From: Asheem Mamoowala Date: Tue, 21 Aug 2018 16:18:51 -0700 Subject: Require minimum side-loaded database user_version=6 --- platform/default/mbgl/storage/offline_database.cpp | 10 ++++++---- test/storage/offline_database.test.cpp | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/platform/default/mbgl/storage/offline_database.cpp b/platform/default/mbgl/storage/offline_database.cpp index 8256912d39..a24c0cf912 100644 --- a/platform/default/mbgl/storage/offline_database.cpp +++ b/platform/default/mbgl/storage/offline_database.cpp @@ -652,11 +652,13 @@ OfflineDatabase::mergeDatabase(const std::string& sideDatabasePath) { return unexpected(std::current_exception()); } try { - // Attaching an accessible path without a db file creates a new temporary - //database and attaches it. Check for matching schema version. + // Support sideloaded databases at user_version = 6. Future schema version + // changes will need to implement migration paths for sideloaded databases at + // version 6. auto sideUserVersion = static_cast(getPragma("PRAGMA side.user_version")); - if (sideUserVersion != 6) { - throw std::runtime_error("Merge database does not match schema or has incorrect user_version"); + const auto mainUserVersion = getPragma("PRAGMA user_version"); + if (sideUserVersion < 6 || sideUserVersion != mainUserVersion) { + throw std::runtime_error("Merge database has incorrect user_version"); } mapbox::sqlite::Transaction transaction(*db); diff --git a/test/storage/offline_database.test.cpp b/test/storage/offline_database.test.cpp index c9e3203abe..7511924d80 100644 --- a/test/storage/offline_database.test.cpp +++ b/test/storage/offline_database.test.cpp @@ -1277,7 +1277,7 @@ TEST(OfflineDatabase, MergeDatabaseWithInvalidPath) { auto result = db.mergeDatabase(filename_sideload); EXPECT_FALSE(result); - EXPECT_EQ(1u, log.count({ EventSeverity::Error, Event::Database, -1, "Merge database does not match schema or has incorrect user_version" })); + EXPECT_EQ(1u, log.count({ EventSeverity::Error, Event::Database, -1, "Merge database has incorrect user_version" })); EXPECT_EQ(0u, log.uncheckedCount()); } -- cgit v1.2.1