diff --git a/C/tests/c4DatabaseTest.cc b/C/tests/c4DatabaseTest.cc index b4d5e6834..8699c5dc9 100644 --- a/C/tests/c4DatabaseTest.cc +++ b/C/tests/c4DatabaseTest.cc @@ -1311,6 +1311,24 @@ TEST_CASE("Database Upgrade From 2.8 with Index", "[Database][Upgrade][C]") { } } +// CBL-6534 +TEST_CASE("Database Upgrade from 3.1 with peerCheckpoints table", "[Database][Upgrade][C]") { + string dbPath = "upgrade_3.1_peerCheckpoints.cblite2"; + + C4DatabaseFlags withFlags{0}; + + SECTION("Revision Tree") {} + SECTION("Version Vector") { withFlags = kC4DB_VersionVectors; } + + C4Log("---- Opening copy of db %s with flags 0x%x", dbPath.c_str(), withFlags); + C4DatabaseConfig2 config = {slice(TempDir()), withFlags}; + auto name = C4Test::copyFixtureDB(kVersionedFixturesSubDir + dbPath); + C4Log("---- copy Fixture to: %s/%s", TempDir().c_str(), name.asString().c_str()); + C4Error err; + c4::ref db = c4db_openNamed(name, &config, WITH_ERROR(&err)); + CHECK(db); +} + static void setRemoteRev(C4Database* db, slice docID, slice revID, C4RemoteID remote) { auto defaultColl = c4db_getDefaultCollection(db, nullptr); C4Document* doc = c4coll_getDoc(defaultColl, docID, true, kDocGetAll, ERROR_INFO()); diff --git a/C/tests/data/db_versions/upgrade_3.1_peerCheckpoints.cblite2/db.sqlite3 b/C/tests/data/db_versions/upgrade_3.1_peerCheckpoints.cblite2/db.sqlite3 new file mode 100644 index 000000000..a8fa1ba2a Binary files /dev/null and b/C/tests/data/db_versions/upgrade_3.1_peerCheckpoints.cblite2/db.sqlite3 differ diff --git a/LiteCore/Storage/SQLiteDataFile.cc b/LiteCore/Storage/SQLiteDataFile.cc index a59ce6c82..61c86adb0 100644 --- a/LiteCore/Storage/SQLiteDataFile.cc +++ b/LiteCore/Storage/SQLiteDataFile.cc @@ -344,17 +344,17 @@ namespace litecore { // Add the 'expiration' column to every KeyStore: for ( string& name : allKeyStoreNames() ) { if ( name.find("::") == string::npos ) { + string tableName = SQLiteKeyStore::tableName(name); string sql; // We need to check for existence of the expiration column first. // Do not add it if it already exists in the table. - if ( getSchema("kv_" + name, "table", "kv_" + name, sql) - && sql.find("expiration") != string::npos ) + if ( getSchema(tableName, "table", tableName, sql) && sql.find("expiration") != string::npos ) continue; // Only update data tables, not FTS index tables _exec(stringprintf( - "ALTER TABLE \"kv_%s\" ADD COLUMN expiration INTEGER; " - "CREATE INDEX \"kv_%s_expiration\" ON \"kv_%s\" (expiration) WHERE expiration not null", - name.c_str(), name.c_str(), name.c_str())); + "ALTER TABLE \"%s\" ADD COLUMN expiration INTEGER; " + "CREATE INDEX \"%s_expiration\" ON \"%s\" (expiration) WHERE expiration not null", + tableName.c_str(), tableName.c_str(), tableName.c_str())); } } });