Bug 1426554 - Add a key-value metadata table to Places. r=mak

MozReview-Commit-ID: 3Q8FQmorZrM

--HG--
extra : rebase_source : f9b8c429f7377e1ee8ce8543d07b178b06c01703
This commit is contained in:
Kit Cambridge 2018-03-03 11:19:22 -08:00
Родитель 7365796c4a
Коммит 2ee395248f
5 изменённых файлов: 43 добавлений и 3 удалений

Просмотреть файл

@ -1233,7 +1233,12 @@ Database::InitSchema(bool* aDatabaseMigrated)
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
} }
// Firefox 61 uses schema version 44. if (currentSchemaVersion < 45) {
rv = MigrateV45Up();
NS_ENSURE_SUCCESS(rv, rv);
}
// Firefox 61 uses schema version 45.
// Schema Upgrades must add migration code here. // Schema Upgrades must add migration code here.
// >>> IMPORTANT! <<< // >>> IMPORTANT! <<<
@ -1318,6 +1323,10 @@ Database::InitSchema(bool* aDatabaseMigrated)
rv = mMainConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_ITEMSANNOS_PLACEATTRIBUTE); rv = mMainConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_ITEMSANNOS_PLACEATTRIBUTE);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
// moz_meta.
rv = mMainConn->ExecuteSimpleSQL(CREATE_MOZ_META);
NS_ENSURE_SUCCESS(rv, rv);
// Initialize the bookmark roots in the new DB. // Initialize the bookmark roots in the new DB.
rv = CreateBookmarkRoots(); rv = CreateBookmarkRoots();
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
@ -2073,6 +2082,20 @@ Database::MigrateV44Up() {
return rv; return rv;
} }
nsresult
Database::MigrateV45Up() {
nsCOMPtr<mozIStorageStatement> metaTableStmt;
nsresult rv = mMainConn->CreateStatement(NS_LITERAL_CSTRING(
"SELECT 1 FROM moz_meta"
), getter_AddRefs(metaTableStmt));
if (NS_FAILED(rv)) {
rv = mMainConn->ExecuteSimpleSQL(CREATE_MOZ_META);
NS_ENSURE_SUCCESS(rv, rv);
}
return NS_OK;
}
nsresult nsresult
Database::GetItemsWithAnno(const nsACString& aAnnoName, int32_t aItemType, Database::GetItemsWithAnno(const nsACString& aAnnoName, int32_t aItemType,
nsTArray<int64_t>& aItemIds) nsTArray<int64_t>& aItemIds)

Просмотреть файл

@ -19,7 +19,7 @@
// This is the schema version. Update it at any schema change and add a // This is the schema version. Update it at any schema change and add a
// corresponding migrateVxx method below. // corresponding migrateVxx method below.
#define DATABASE_SCHEMA_VERSION 44 #define DATABASE_SCHEMA_VERSION 45
// Fired after Places inited. // Fired after Places inited.
#define TOPIC_PLACES_INIT_COMPLETE "places-init-complete" #define TOPIC_PLACES_INIT_COMPLETE "places-init-complete"
@ -305,6 +305,7 @@ protected:
nsresult MigrateV42Up(); nsresult MigrateV42Up();
nsresult MigrateV43Up(); nsresult MigrateV43Up();
nsresult MigrateV44Up(); nsresult MigrateV44Up();
nsresult MigrateV45Up();
nsresult UpdateBookmarkRootTitles(); nsresult UpdateBookmarkRootTitles();

Просмотреть файл

@ -221,4 +221,15 @@
") WITHOUT ROWID " \ ") WITHOUT ROWID " \
) )
// This table holds key-value metadata for Places and its consumers. Sync stores
// the sync IDs for the bookmarks and history collections in this table, and the
// last sync time for history.
#define CREATE_MOZ_META NS_LITERAL_CSTRING( \
"CREATE TABLE moz_meta (" \
"key TEXT PRIMARY KEY, " \
"value NOT NULL" \
") WITHOUT ROWID " \
)
#endif // __nsPlacesTables_h__ #endif // __nsPlacesTables_h__

Просмотреть файл

@ -3,7 +3,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const CURRENT_SCHEMA_VERSION = 44; const CURRENT_SCHEMA_VERSION = 45;
const FIRST_UPGRADABLE_SCHEMA_VERSION = 30; const FIRST_UPGRADABLE_SCHEMA_VERSION = 30;
const NS_APP_USER_PROFILE_50_DIR = "ProfD"; const NS_APP_USER_PROFILE_50_DIR = "ProfD";

Просмотреть файл

@ -208,3 +208,8 @@ add_task(async function test_no_orphan_keywords() {
Assert.equal(rows.length, 0, Assert.equal(rows.length, 0,
`Should have no orphan keywords.`); `Should have no orphan keywords.`);
}); });
add_task(async function test_meta_exists() {
let db = await PlacesUtils.promiseDBConnection();
await db.execute(`SELECT 1 FROM moz_meta`);
});