From 2e1e0e26417bd58046d591ea2a8bb95efc5665ff Mon Sep 17 00:00:00 2001 From: Marco Bonardo Date: Tue, 8 Aug 2023 17:12:12 +0000 Subject: [PATCH] Bug 1847592 - Remove some old Places migrations and move schema version to the history service interface. r=places-reviewers,lina Since Firefox 72 was a watershed release, thus any upgrade of previous versions must go through it, we can remove some old migrations. We stop removing at Firefox 68, that was the last ESR before the watershed. Also while there move the schema version to the history service so we don't have to manually keep the migration test header in sync. Differential Revision: https://phabricator.services.mozilla.com/D185576 --- toolkit/components/places/Database.cpp | 660 +----------------- toolkit/components/places/Database.h | 18 +- .../places/nsINavHistoryService.idl | 5 + .../maintenance/test_corrupt_places_schema.js | 2 +- .../test_places_replaceOnStartup.js | 2 +- .../test_places_replaceOnStartup_clone.js | 2 +- .../places/tests/migration/head_migration.js | 4 +- .../places/tests/migration/places_v43.sqlite | Bin 1146880 -> 0 bytes .../places/tests/migration/places_v52.sqlite | 0 .../tests/migration/test_current_from_v43.js | 253 ------- .../tests/migration/test_current_from_v45.js | 100 --- .../tests/migration/test_current_from_v46.js | 52 -- .../tests/migration/test_current_from_v47.js | 128 ---- .../tests/migration/test_current_from_v48.js | 190 ----- .../tests/migration/test_current_from_v50.js | 209 ------ .../tests/migration/test_current_from_v53.js | 2 +- .../places/tests/migration/xpcshell.ini | 8 +- 17 files changed, 22 insertions(+), 1613 deletions(-) delete mode 100644 toolkit/components/places/tests/migration/places_v43.sqlite create mode 100644 toolkit/components/places/tests/migration/places_v52.sqlite delete mode 100644 toolkit/components/places/tests/migration/test_current_from_v43.js delete mode 100644 toolkit/components/places/tests/migration/test_current_from_v45.js delete mode 100644 toolkit/components/places/tests/migration/test_current_from_v46.js delete mode 100644 toolkit/components/places/tests/migration/test_current_from_v47.js delete mode 100644 toolkit/components/places/tests/migration/test_current_from_v48.js delete mode 100644 toolkit/components/places/tests/migration/test_current_from_v50.js diff --git a/toolkit/components/places/Database.cpp b/toolkit/components/places/Database.cpp index e2f5cc4cecf8..d090d399f75a 100644 --- a/toolkit/components/places/Database.cpp +++ b/toolkit/components/places/Database.cpp @@ -7,7 +7,6 @@ #include "mozilla/DebugOnly.h" #include "mozilla/ScopeExit.h" #include "mozilla/SpinEventLoopUntil.h" -#include "mozilla/JSONStringWriteFuncs.h" #include "mozilla/StaticPrefs_places.h" #include "Database.h" @@ -71,9 +70,6 @@ #define ENV_ALLOW_CORRUPTION \ "ALLOW_PLACES_DATABASE_TO_LOSE_DATA_AND_BECOME_CORRUPT" -#define PREF_MIGRATE_V52_ORIGIN_FRECENCIES \ - "places.database.migrateV52OriginFrecencies" - // Maximum size for the WAL file. // For performance reasons this should be as large as possible, so that more // transactions can fit into it, and the checkpoint cost is paid less often. @@ -1076,17 +1072,12 @@ nsresult Database::InitSchema(bool* aDatabaseMigrated) { NS_ENSURE_SUCCESS(rv, rv); bool databaseInitialized = currentSchemaVersion > 0; - if (databaseInitialized && currentSchemaVersion == DATABASE_SCHEMA_VERSION) { + if (databaseInitialized && + currentSchemaVersion == nsINavHistoryService::DATABASE_SCHEMA_VERSION) { // The database is up to date and ready to go. return NS_OK; } - auto guard = MakeScopeExit([&]() { - // These run at the end of the migration, out of the transaction, - // regardless of its success. - MigrateV52OriginFrecencies(); - }); - // We are going to update the database, so everything from now on should be in // a transaction for performances. mozStorageTransaction transaction(mMainConn, false); @@ -1106,64 +1097,15 @@ nsresult Database::InitSchema(bool* aDatabaseMigrated) { // The only thing we will do for downgrades is setting back the schema // version, so that next upgrades will run again the migration step. - if (currentSchemaVersion < DATABASE_SCHEMA_VERSION) { + if (currentSchemaVersion < nsINavHistoryService::DATABASE_SCHEMA_VERSION) { *aDatabaseMigrated = true; - if (currentSchemaVersion < 43) { - // These are versions older than Firefox 60 ESR that are not supported + if (currentSchemaVersion < 52) { + // These are versions older than Firefox 68 ESR that are not supported // anymore. In this case it's safer to just replace the database. return NS_ERROR_FILE_CORRUPTED; } - // Firefox 60 uses schema version 43. - This is an ESR. - - if (currentSchemaVersion < 44) { - rv = MigrateV44Up(); - NS_ENSURE_SUCCESS(rv, rv); - } - - if (currentSchemaVersion < 45) { - rv = MigrateV45Up(); - NS_ENSURE_SUCCESS(rv, rv); - } - - if (currentSchemaVersion < 46) { - rv = MigrateV46Up(); - NS_ENSURE_SUCCESS(rv, rv); - } - - if (currentSchemaVersion < 47) { - rv = MigrateV47Up(); - NS_ENSURE_SUCCESS(rv, rv); - } - - // Firefox 61 uses schema version 47. - - if (currentSchemaVersion < 48) { - rv = MigrateV48Up(); - NS_ENSURE_SUCCESS(rv, rv); - } - - if (currentSchemaVersion < 49) { - rv = MigrateV49Up(); - NS_ENSURE_SUCCESS(rv, rv); - } - - if (currentSchemaVersion < 50) { - rv = MigrateV50Up(); - NS_ENSURE_SUCCESS(rv, rv); - } - - if (currentSchemaVersion < 51) { - rv = MigrateV51Up(); - NS_ENSURE_SUCCESS(rv, rv); - } - - if (currentSchemaVersion < 52) { - rv = MigrateV52Up(); - NS_ENSURE_SUCCESS(rv, rv); - } - // Firefox 62 uses schema version 52. // Firefox 68 uses schema version 52. - This is an ESR. @@ -1173,7 +1115,7 @@ nsresult Database::InitSchema(bool* aDatabaseMigrated) { } // Firefox 69 uses schema version 53 - // Firefox 78 uses schema version 53 - This is an ESR. + // Firefox 72 is a watershed release. if (currentSchemaVersion < 54) { rv = MigrateV54Up(); @@ -1409,7 +1351,8 @@ nsresult Database::InitSchema(bool* aDatabaseMigrated) { } // Set the schema version to the current one. - rv = mMainConn->SetSchemaVersion(DATABASE_SCHEMA_VERSION); + rv = mMainConn->SetSchemaVersion( + nsINavHistoryService::DATABASE_SCHEMA_VERSION); NS_ENSURE_SUCCESS(rv, rv); rv = transaction.Commit(); @@ -1742,518 +1685,6 @@ nsresult Database::InitTempEntities() { return NS_OK; } -nsresult Database::MigrateV44Up() { - // We need to remove any non-builtin roots and their descendants. - - // Install a temp trigger to clean up linked tables when the main - // bookmarks are deleted. - nsresult rv = mMainConn->ExecuteSimpleSQL(nsLiteralCString( - "CREATE TEMP TRIGGER moz_migrate_bookmarks_trigger " - "AFTER DELETE ON moz_bookmarks FOR EACH ROW " - "BEGIN " - // Insert tombstones. - "INSERT OR IGNORE INTO moz_bookmarks_deleted (guid, dateRemoved) " - "VALUES (OLD.guid, strftime('%s', 'now', 'localtime', 'utc') * 1000000); " - // Remove old annotations for the bookmarks. - "DELETE FROM moz_items_annos " - "WHERE item_id = OLD.id; " - // Decrease the foreign_count in moz_places. - "UPDATE moz_places " - "SET foreign_count = foreign_count - 1 " - "WHERE id = OLD.fk; " - "END ")); - if (NS_FAILED(rv)) return rv; - - // This trigger listens for moz_places deletes, and updates moz_annos and - // moz_keywords accordingly. - rv = mMainConn->ExecuteSimpleSQL(nsLiteralCString( - "CREATE TEMP TRIGGER moz_migrate_annos_trigger " - "AFTER UPDATE ON moz_places FOR EACH ROW " - // Only remove from moz_places if we don't have any remaining keywords - // pointing to this place, and it hasn't been visited. Note: orphan - // keywords are tidied up below. - "WHEN NEW.visit_count = 0 AND " - " NEW.foreign_count = (SELECT COUNT(*) FROM moz_keywords WHERE place_id " - "= NEW.id) " - "BEGIN " - // No more references to the place, so we can delete the place itself. - "DELETE FROM moz_places " - "WHERE id = NEW.id; " - // Delete annotations relating to the place. - "DELETE FROM moz_annos " - "WHERE place_id = NEW.id; " - // Delete keywords relating to the place. - "DELETE FROM moz_keywords " - "WHERE place_id = NEW.id; " - "END ")); - if (NS_FAILED(rv)) return rv; - - // Listens to moz_keyword deletions, to ensure moz_places gets the - // foreign_count updated corrrectly. - rv = mMainConn->ExecuteSimpleSQL( - nsLiteralCString("CREATE TEMP TRIGGER moz_migrate_keyword_trigger " - "AFTER DELETE ON moz_keywords FOR EACH ROW " - "BEGIN " - // If we remove a keyword, then reduce the foreign_count. - "UPDATE moz_places " - "SET foreign_count = foreign_count - 1 " - "WHERE id = OLD.place_id; " - "END ")); - if (NS_FAILED(rv)) return rv; - - // First of all, find the non-builtin roots. - nsCOMPtr deleteStmt; - rv = mMainConn->CreateStatement( - nsLiteralCString("WITH RECURSIVE " - "itemsToRemove(id, guid) AS ( " - "SELECT b.id, b.guid FROM moz_bookmarks b " - "JOIN moz_bookmarks p ON b.parent = p.id " - "WHERE p.guid = 'root________' AND " - "b.guid NOT IN ('menu________', 'toolbar_____', " - "'tags________', 'unfiled_____', 'mobile______') " - "UNION ALL " - "SELECT b.id, b.guid FROM moz_bookmarks b " - "JOIN itemsToRemove d ON d.id = b.parent " - "WHERE b.guid NOT IN ('menu________', 'toolbar_____', " - "'tags________', 'unfiled_____', 'mobile______') " - ") " - "DELETE FROM moz_bookmarks " - "WHERE id IN (SELECT id FROM itemsToRemove) "), - getter_AddRefs(deleteStmt)); - if (NS_FAILED(rv)) return rv; - - rv = deleteStmt->Execute(); - if (NS_FAILED(rv)) return rv; - - // Before we remove the triggers, check for keywords attached to places which - // no longer have a bookmark to them. We do this before removing the triggers, - // so that we can make use of the keyword trigger to update the counts in - // moz_places. - rv = mMainConn->ExecuteSimpleSQL( - nsLiteralCString("DELETE FROM moz_keywords WHERE place_id IN ( " - "SELECT h.id FROM moz_keywords k " - "JOIN moz_places h ON h.id = k.place_id " - "GROUP BY place_id HAVING h.foreign_count = count(*) " - ")")); - if (NS_FAILED(rv)) return rv; - - // Now remove the temp triggers. - rv = mMainConn->ExecuteSimpleSQL( - "DROP TRIGGER moz_migrate_bookmarks_trigger "_ns); - if (NS_FAILED(rv)) return rv; - rv = - mMainConn->ExecuteSimpleSQL("DROP TRIGGER moz_migrate_annos_trigger "_ns); - if (NS_FAILED(rv)) return rv; - rv = mMainConn->ExecuteSimpleSQL( - "DROP TRIGGER moz_migrate_keyword_trigger "_ns); - if (NS_FAILED(rv)) return rv; - - // Cleanup any orphan annotation attributes. - rv = mMainConn->ExecuteSimpleSQL( - nsLiteralCString("DELETE FROM moz_anno_attributes WHERE id IN ( " - "SELECT id FROM moz_anno_attributes n " - "EXCEPT " - "SELECT DISTINCT anno_attribute_id FROM moz_annos " - "EXCEPT " - "SELECT DISTINCT anno_attribute_id FROM moz_items_annos " - ")")); - if (NS_FAILED(rv)) return rv; - - return NS_OK; -} - -nsresult Database::MigrateV45Up() { - nsCOMPtr metaTableStmt; - nsresult rv = mMainConn->CreateStatement("SELECT 1 FROM moz_meta"_ns, - getter_AddRefs(metaTableStmt)); - if (NS_FAILED(rv)) { - rv = mMainConn->ExecuteSimpleSQL(CREATE_MOZ_META); - NS_ENSURE_SUCCESS(rv, rv); - } - return NS_OK; -} - -nsresult Database::MigrateV46Up() { - // Convert the existing queries. For simplicity we assume the user didn't - // edit these queries, and just do a 1:1 conversion. - nsresult rv = mMainConn->ExecuteSimpleSQL(nsLiteralCString( - "UPDATE moz_places " - "SET url = IFNULL('place:tag=' || ( " - "SELECT title FROM moz_bookmarks " - "WHERE id = CAST(get_query_param(substr(url, 7), 'folder') AS INT) " - "), url) " - "WHERE url_hash BETWEEN hash('place', 'prefix_lo') AND " - "hash('place', 'prefix_hi') " - "AND url LIKE '%type=7%' " - "AND EXISTS(SELECT 1 FROM moz_bookmarks " - "WHERE id = CAST(get_query_param(substr(url, 7), 'folder') AS INT)) ")); - - // Recalculate hashes for all tag queries. - rv = mMainConn->ExecuteSimpleSQL( - nsLiteralCString("UPDATE moz_places SET url_hash = hash(url) " - "WHERE url_hash BETWEEN hash('place', 'prefix_lo') AND " - "hash('place', 'prefix_hi') " - "AND url LIKE '%tag=%' ")); - NS_ENSURE_SUCCESS(rv, rv); - - // Update Sync fields for all tag queries. - rv = mMainConn->ExecuteSimpleSQL(nsLiteralCString( - "UPDATE moz_bookmarks SET syncChangeCounter = syncChangeCounter + 1 " - "WHERE fk IN ( " - "SELECT id FROM moz_places " - "WHERE url_hash BETWEEN hash('place', 'prefix_lo') AND " - "hash('place', 'prefix_hi') " - "AND url LIKE '%tag=%' " - ") ")); - NS_ENSURE_SUCCESS(rv, rv); - return NS_OK; -} - -nsresult Database::MigrateV47Up() { - // v46 may have mistakenly set some url to NULL, we must fix those. - // Since the original url was an invalid query, we replace NULLs with an - // empty query. - nsresult rv = mMainConn->ExecuteSimpleSQL( - nsLiteralCString("UPDATE moz_places " - "SET url = 'place:excludeItems=1', url_hash = " - "hash('place:excludeItems=1') " - "WHERE url ISNULL ")); - NS_ENSURE_SUCCESS(rv, rv); - // Update Sync fields for these queries. - rv = mMainConn->ExecuteSimpleSQL(nsLiteralCString( - "UPDATE moz_bookmarks SET syncChangeCounter = syncChangeCounter + 1 " - "WHERE fk IN ( " - "SELECT id FROM moz_places " - "WHERE url_hash = hash('place:excludeItems=1') " - "AND url = 'place:excludeItems=1' " - ") ")); - NS_ENSURE_SUCCESS(rv, rv); - return NS_OK; -} - -nsresult Database::MigrateV48Up() { - // Create and populate moz_origins. - nsCOMPtr stmt; - nsresult rv = mMainConn->CreateStatement("SELECT * FROM moz_origins; "_ns, - getter_AddRefs(stmt)); - if (NS_FAILED(rv)) { - rv = mMainConn->ExecuteSimpleSQL(CREATE_MOZ_ORIGINS); - NS_ENSURE_SUCCESS(rv, rv); - } - rv = mMainConn->ExecuteSimpleSQL(nsLiteralCString( - "INSERT OR IGNORE INTO moz_origins (prefix, host, frecency) " - "SELECT get_prefix(url), get_host_and_port(url), -1 " - "FROM moz_places; ")); - NS_ENSURE_SUCCESS(rv, rv); - - // Add and populate moz_places.origin_id. - rv = mMainConn->CreateStatement("SELECT origin_id FROM moz_places; "_ns, - getter_AddRefs(stmt)); - if (NS_FAILED(rv)) { - rv = mMainConn->ExecuteSimpleSQL(nsLiteralCString( - "ALTER TABLE moz_places " - "ADD COLUMN origin_id INTEGER REFERENCES moz_origins(id); ")); - NS_ENSURE_SUCCESS(rv, rv); - } - rv = mMainConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_PLACES_ORIGIN_ID); - NS_ENSURE_SUCCESS(rv, rv); - rv = mMainConn->ExecuteSimpleSQL(nsLiteralCString( - "UPDATE moz_places " - "SET origin_id = ( " - "SELECT id FROM moz_origins " - "WHERE prefix = get_prefix(url) AND host = get_host_and_port(url) " - "); ")); - NS_ENSURE_SUCCESS(rv, rv); - - // From this point on, nobody should use moz_hosts again. Empty it so that we - // don't leak the user's history, but don't remove it yet so that the user can - // downgrade. - // This can fail, if moz_hosts doesn't exist anymore, that is what happens in - // case of downgrade+upgrade. - Unused << mMainConn->ExecuteSimpleSQL("DELETE FROM moz_hosts; "_ns); - - return NS_OK; -} - -nsresult Database::MigrateV49Up() { - // These hidden preferences were added along with the v48 migration as part of - // the frecency stats implementation but are now replaced with entries in the - // moz_meta table. - Unused << Preferences::ClearUser("places.frecency.stats.count"); - Unused << Preferences::ClearUser("places.frecency.stats.sum"); - Unused << Preferences::ClearUser("places.frecency.stats.sumOfSquares"); - return NS_OK; -} - -nsresult Database::MigrateV50Up() { - // Convert the existing queries. We don't have REGEX available, so the - // simplest thing to do is to pull the urls out, and process them manually. - nsCOMPtr stmt; - nsresult rv = mMainConn->CreateStatement( - nsLiteralCString("SELECT id, url FROM moz_places " - "WHERE url_hash BETWEEN hash('place', 'prefix_lo') AND " - "hash('place', 'prefix_hi') " - "AND url LIKE '%folder=%' "), - getter_AddRefs(stmt)); - if (NS_FAILED(rv)) return rv; - - AutoTArray, 32> placeURLs; - - bool hasMore = false; - nsCString url; - while (NS_SUCCEEDED(stmt->ExecuteStep(&hasMore)) && hasMore) { - int64_t placeId; - rv = stmt->GetInt64(0, &placeId); - if (NS_FAILED(rv)) return rv; - rv = stmt->GetUTF8String(1, url); - if (NS_FAILED(rv)) return rv; - - // XXX(Bug 1631371) Check if this should use a fallible operation as it - // pretended earlier. - placeURLs.AppendElement(std::make_pair(placeId, url)); - } - - if (placeURLs.IsEmpty()) { - return NS_OK; - } - - int64_t placeId; - for (uint32_t i = 0; i < placeURLs.Length(); ++i) { - placeId = placeURLs[i].first; - url = placeURLs[i].second; - - rv = ConvertOldStyleQuery(url); - // Something bad happened, and we can't convert it, so just continue. - if (NS_WARN_IF(NS_FAILED(rv))) { - continue; - } - - nsCOMPtr updateStmt; - rv = mMainConn->CreateStatement( - nsLiteralCString("UPDATE moz_places " - "SET url = :url, url_hash = hash(:url) " - "WHERE id = :placeId "), - getter_AddRefs(updateStmt)); - if (NS_FAILED(rv)) return rv; - - rv = URIBinder::Bind(updateStmt, "url"_ns, url); - if (NS_FAILED(rv)) return rv; - rv = updateStmt->BindInt64ByName("placeId"_ns, placeId); - if (NS_FAILED(rv)) return rv; - - rv = updateStmt->Execute(); - if (NS_FAILED(rv)) return rv; - - // Update Sync fields for these queries. - nsCOMPtr syncStmt; - rv = mMainConn->CreateStatement( - nsLiteralCString("UPDATE moz_bookmarks SET syncChangeCounter = " - "syncChangeCounter + 1 " - "WHERE fk = :placeId "), - getter_AddRefs(syncStmt)); - if (NS_FAILED(rv)) return rv; - - rv = syncStmt->BindInt64ByName("placeId"_ns, placeId); - if (NS_FAILED(rv)) return rv; - - rv = syncStmt->Execute(); - if (NS_FAILED(rv)) return rv; - } - - return NS_OK; -} - -nsresult Database::MigrateV51Up() { - nsCOMPtr stmt; - nsresult rv = mMainConn->CreateStatement( - nsLiteralCString("SELECT b.guid FROM moz_anno_attributes n " - "JOIN moz_items_annos a ON n.id = a.anno_attribute_id " - "JOIN moz_bookmarks b ON a.item_id = b.id " - "WHERE n.name = :anno_name ORDER BY a.content DESC"), - getter_AddRefs(stmt)); - if (NS_FAILED(rv)) { - MOZ_ASSERT(false, - "Should succeed unless item annotations table has been removed"); - return NS_OK; - }; - - rv = stmt->BindUTF8StringByName("anno_name"_ns, LAST_USED_ANNO); - NS_ENSURE_SUCCESS(rv, rv); - - JSONStringWriteFunc json; - JSONWriter jw{json}; - jw.StartArrayProperty(nullptr, JSONWriter::SingleLineStyle); - - bool hasAtLeastOne = false; - bool hasMore = false; - uint32_t length; - while (NS_SUCCEEDED(stmt->ExecuteStep(&hasMore)) && hasMore) { - hasAtLeastOne = true; - const char* stmtString = stmt->AsSharedUTF8String(0, &length); - jw.StringElement(Span(stmtString, length)); - } - jw.EndArray(); - - // If we don't have any, just abort early and save the extra work. - if (!hasAtLeastOne) { - return NS_OK; - } - - rv = mMainConn->CreateStatement( - nsLiteralCString("INSERT OR REPLACE INTO moz_meta " - "VALUES (:key, :value) "), - getter_AddRefs(stmt)); - NS_ENSURE_SUCCESS(rv, rv); - - rv = stmt->BindUTF8StringByName("key"_ns, LAST_USED_FOLDERS_META_KEY); - NS_ENSURE_SUCCESS(rv, rv); - rv = stmt->BindUTF8StringByName("value"_ns, json.StringCRef()); - NS_ENSURE_SUCCESS(rv, rv); - rv = stmt->Execute(); - NS_ENSURE_SUCCESS(rv, rv); - - // Clean up the now redundant annotations. - rv = mMainConn->CreateStatement( - nsLiteralCString( - "DELETE FROM moz_items_annos WHERE anno_attribute_id = " - "(SELECT id FROM moz_anno_attributes WHERE name = :anno_name) "), - getter_AddRefs(stmt)); - NS_ENSURE_SUCCESS(rv, rv); - rv = stmt->BindUTF8StringByName("anno_name"_ns, LAST_USED_ANNO); - NS_ENSURE_SUCCESS(rv, rv); - rv = stmt->Execute(); - NS_ENSURE_SUCCESS(rv, rv); - - rv = mMainConn->CreateStatement( - nsLiteralCString( - "DELETE FROM moz_anno_attributes WHERE name = :anno_name "), - getter_AddRefs(stmt)); - NS_ENSURE_SUCCESS(rv, rv); - rv = stmt->BindUTF8StringByName("anno_name"_ns, LAST_USED_ANNO); - NS_ENSURE_SUCCESS(rv, rv); - rv = stmt->Execute(); - NS_ENSURE_SUCCESS(rv, rv); - - return NS_OK; -} - -namespace { - -class MigrateV52OriginFrecenciesRunnable final : public Runnable { - public: - NS_DECL_NSIRUNNABLE - explicit MigrateV52OriginFrecenciesRunnable(mozIStorageConnection* aDBConn); - - private: - nsCOMPtr mDBConn; -}; - -MigrateV52OriginFrecenciesRunnable::MigrateV52OriginFrecenciesRunnable( - mozIStorageConnection* aDBConn) - : Runnable("places::MigrateV52OriginFrecenciesRunnable"), - mDBConn(aDBConn) {} - -NS_IMETHODIMP -MigrateV52OriginFrecenciesRunnable::Run() { - if (NS_IsMainThread()) { - // Migration done. Clear the pref. - Unused << Preferences::ClearUser(PREF_MIGRATE_V52_ORIGIN_FRECENCIES); - - // Now that frecencies have been migrated, recalculate the origin frecency - // stats. - nsNavHistory* navHistory = nsNavHistory::GetHistoryService(); - NS_ENSURE_STATE(navHistory); - nsresult rv = navHistory->RecalculateOriginFrecencyStats(nullptr); - NS_ENSURE_SUCCESS(rv, rv); - - return NS_OK; - } - - // We do the work in chunks, or the wal journal may grow too much. - nsresult rv = mDBConn->ExecuteSimpleSQL(nsLiteralCString( - "UPDATE moz_origins " - "SET frecency = ( " - "SELECT CAST(TOTAL(frecency) AS INTEGER) " - "FROM moz_places " - "WHERE frecency > 0 AND moz_places.origin_id = moz_origins.id " - ") " - "WHERE id IN ( " - "SELECT id " - "FROM moz_origins " - "WHERE frecency < 0 " - "LIMIT 400 " - ") ")); - NS_ENSURE_SUCCESS(rv, rv); - - nsCOMPtr selectStmt; - rv = mDBConn->CreateStatement(nsLiteralCString("SELECT 1 " - "FROM moz_origins " - "WHERE frecency < 0 " - "LIMIT 1 "), - getter_AddRefs(selectStmt)); - NS_ENSURE_SUCCESS(rv, rv); - bool hasResult = false; - rv = selectStmt->ExecuteStep(&hasResult); - NS_ENSURE_SUCCESS(rv, rv); - if (hasResult) { - // There are more results to handle. Re-dispatch to the same thread for the - // next chunk. - return NS_DispatchToCurrentThread(this); - } - - // Re-dispatch to the main-thread to flip the migration pref. - return NS_DispatchToMainThread(this); -} - -} // namespace - -void Database::MigrateV52OriginFrecencies() { - MOZ_ASSERT(NS_IsMainThread()); - - if (!Preferences::GetBool(PREF_MIGRATE_V52_ORIGIN_FRECENCIES)) { - // The migration has already been completed. - return; - } - - RefPtr runnable( - new MigrateV52OriginFrecenciesRunnable(mMainConn)); - nsCOMPtr target(do_GetInterface(mMainConn)); - MOZ_ASSERT(target); - if (target) { - Unused << target->Dispatch(runnable, NS_DISPATCH_NORMAL); - } -} - -nsresult Database::MigrateV52Up() { - // Before this migration, moz_origin.frecency is the max frecency of all - // places with the origin. After this migration, it's the sum of frecencies - // of all places with the origin. - // - // Setting this pref will cause InitSchema to begin async migration, via - // MigrateV52OriginFrecencies. When that migration is done, origin frecency - // stats are recalculated (see MigrateV52OriginFrecenciesRunnable::Run). - Unused << Preferences::SetBool(PREF_MIGRATE_V52_ORIGIN_FRECENCIES, true); - - // Set all origin frecencies to -1 so that MigrateV52OriginFrecenciesRunnable - // will migrate them. - nsresult rv = - mMainConn->ExecuteSimpleSQL("UPDATE moz_origins SET frecency = -1 "_ns); - NS_ENSURE_SUCCESS(rv, rv); - - // This migration also renames these moz_meta keys that keep track of frecency - // stats. (That happens when stats are recalculated.) Delete the old ones. - rv = - mMainConn->ExecuteSimpleSQL(nsLiteralCString("DELETE FROM moz_meta " - "WHERE key IN ( " - "'frecency_count', " - "'frecency_sum', " - "'frecency_sum_of_squares' " - ") ")); - NS_ENSURE_SUCCESS(rv, rv); - - return NS_OK; -} - nsresult Database::MigrateV53Up() { nsCOMPtr stmt; nsresult rv = mMainConn->CreateStatement("SELECT 1 FROM moz_items_annos"_ns, @@ -2599,81 +2030,6 @@ nsresult Database::RecalculateOriginFrecencyStatsInternal() { ") ")); } -nsresult Database::ConvertOldStyleQuery(nsCString& aURL) { - AutoTArray tokens; - nsresult rv = TokenizeQueryString(aURL, &tokens); - NS_ENSURE_SUCCESS(rv, rv); - - AutoTArray newTokens; - bool invalid = false; - nsAutoCString guid; - - for (uint32_t j = 0; j < tokens.Length(); ++j) { - const QueryKeyValuePair& kvp = tokens[j]; - - if (!kvp.key.EqualsLiteral("folder")) { - // XXX(Bug 1631371) Check if this should use a fallible operation as it - // pretended earlier. - newTokens.AppendElement(kvp); - continue; - } - - int64_t itemId = kvp.value.ToInteger(&rv); - if (NS_SUCCEEDED(rv)) { - // We have the folder's ID, now to find its GUID. - nsCOMPtr stmt; - nsresult rv = mMainConn->CreateStatement( - nsLiteralCString("SELECT guid FROM moz_bookmarks " - "WHERE id = :itemId "), - getter_AddRefs(stmt)); - if (NS_FAILED(rv)) return rv; - - rv = stmt->BindInt64ByName("itemId"_ns, itemId); - if (NS_FAILED(rv)) return rv; - - bool hasMore = false; - if (NS_SUCCEEDED(stmt->ExecuteStep(&hasMore)) && hasMore) { - rv = stmt->GetUTF8String(0, guid); - if (NS_FAILED(rv)) return rv; - } - } else if (kvp.value.EqualsLiteral("PLACES_ROOT")) { - guid = nsLiteralCString(ROOT_GUID); - } else if (kvp.value.EqualsLiteral("BOOKMARKS_MENU")) { - guid = nsLiteralCString(MENU_ROOT_GUID); - } else if (kvp.value.EqualsLiteral("TAGS")) { - guid = nsLiteralCString(TAGS_ROOT_GUID); - } else if (kvp.value.EqualsLiteral("UNFILED_BOOKMARKS")) { - guid = nsLiteralCString(UNFILED_ROOT_GUID); - } else if (kvp.value.EqualsLiteral("TOOLBAR")) { - guid = nsLiteralCString(TOOLBAR_ROOT_GUID); - } else if (kvp.value.EqualsLiteral("MOBILE_BOOKMARKS")) { - guid = nsLiteralCString(MOBILE_ROOT_GUID); - } - - QueryKeyValuePair* newPair; - if (guid.IsEmpty()) { - // This is invalid, so we'll change this key/value pair to something else - // so that the query remains a valid url. - newPair = new QueryKeyValuePair("invalidOldParentId"_ns, kvp.value); - invalid = true; - } else { - newPair = new QueryKeyValuePair("parent"_ns, guid); - } - // XXX(Bug 1631371) Check if this should use a fallible operation as it - // pretended earlier. - newTokens.AppendElement(*newPair); - delete newPair; - } - - if (invalid) { - // One or more of the folders don't exist, replace with an empty query. - newTokens.AppendElement(QueryKeyValuePair("excludeItems"_ns, "1"_ns)); - } - - TokensToQueryString(newTokens, aURL); - return NS_OK; -} - int64_t Database::CreateMobileRoot() { MOZ_ASSERT(NS_IsMainThread()); diff --git a/toolkit/components/places/Database.h b/toolkit/components/places/Database.h index e18dec7567ef..74d0ba748a2d 100644 --- a/toolkit/components/places/Database.h +++ b/toolkit/components/places/Database.h @@ -16,10 +16,6 @@ #include "Shutdown.h" #include "nsCategoryCache.h" -// This is the schema version. Update it at any schema change and add a -// corresponding migrateVxx method below. -#define DATABASE_SCHEMA_VERSION 75 - // Fired after Places inited. #define TOPIC_PLACES_INIT_COMPLETE "places-init-complete" // This topic is received when the profile is about to be lost. Places does @@ -295,16 +291,9 @@ class Database final : public nsIObserver, public nsSupportsWeakReference { /** * Helpers used by schema upgrades. + * When adding a new function remember to bump up the schema version in + * nsINavHistoryService. */ - nsresult MigrateV44Up(); - nsresult MigrateV45Up(); - nsresult MigrateV46Up(); - nsresult MigrateV47Up(); - nsresult MigrateV48Up(); - nsresult MigrateV49Up(); - nsresult MigrateV50Up(); - nsresult MigrateV51Up(); - nsresult MigrateV52Up(); nsresult MigrateV53Up(); nsresult MigrateV54Up(); nsresult MigrateV55Up(); @@ -321,14 +310,11 @@ class Database final : public nsIObserver, public nsSupportsWeakReference { nsresult MigrateV74Up(); nsresult MigrateV75Up(); - void MigrateV52OriginFrecencies(); - nsresult UpdateBookmarkRootTitles(); friend class ConnectionShutdownBlocker; int64_t CreateMobileRoot(); - nsresult ConvertOldStyleQuery(nsCString& aURL); private: ~Database(); diff --git a/toolkit/components/places/nsINavHistoryService.idl b/toolkit/components/places/nsINavHistoryService.idl index a252bfbf145a..1a23762e1bfd 100644 --- a/toolkit/components/places/nsINavHistoryService.idl +++ b/toolkit/components/places/nsINavHistoryService.idl @@ -925,6 +925,11 @@ interface nsINavHistoryQueryOptions : nsISupports [scriptable, uuid(20c974ff-ee16-4828-9326-1b7c9e036622)] interface nsINavHistoryService : nsISupports { + // The current database schema version. + // To migrate to a new version bump this, add a MigrateVXXUp function to + // Database.cpp/h, and a test into tests/migration/ + const unsigned long DATABASE_SCHEMA_VERSION = 75; + /** * System Notifications: * diff --git a/toolkit/components/places/tests/maintenance/test_corrupt_places_schema.js b/toolkit/components/places/tests/maintenance/test_corrupt_places_schema.js index 9af7863ca208..1592378ae080 100644 --- a/toolkit/components/places/tests/maintenance/test_corrupt_places_schema.js +++ b/toolkit/components/places/tests/maintenance/test_corrupt_places_schema.js @@ -4,7 +4,7 @@ // Tests that history initialization correctly handles a corrupt places schema. add_task(async function () { - let path = await setupPlacesDatabase(["migration", "places_v43.sqlite"]); + let path = await setupPlacesDatabase(["migration", "places_v52.sqlite"]); // Ensure the database will go through a migration that depends on moz_places // and break the schema by dropping that table. diff --git a/toolkit/components/places/tests/maintenance/test_places_replaceOnStartup.js b/toolkit/components/places/tests/maintenance/test_places_replaceOnStartup.js index dae5154df43b..0c389bb18dab 100644 --- a/toolkit/components/places/tests/maintenance/test_places_replaceOnStartup.js +++ b/toolkit/components/places/tests/maintenance/test_places_replaceOnStartup.js @@ -6,7 +6,7 @@ add_task(async function () { await test_database_replacement( - ["migration", "places_v43.sqlite"], + ["migration", "places_v52.sqlite"], "places.sqlite", false, PlacesUtils.history.DATABASE_STATUS_CORRUPT diff --git a/toolkit/components/places/tests/maintenance/test_places_replaceOnStartup_clone.js b/toolkit/components/places/tests/maintenance/test_places_replaceOnStartup_clone.js index d2ef1374e9cb..7b984a2befba 100644 --- a/toolkit/components/places/tests/maintenance/test_places_replaceOnStartup_clone.js +++ b/toolkit/components/places/tests/maintenance/test_places_replaceOnStartup_clone.js @@ -6,7 +6,7 @@ add_task(async function () { await test_database_replacement( - ["migration", "places_v43.sqlite"], + ["migration", "places_v52.sqlite"], "places.sqlite", true, PlacesUtils.history.DATABASE_STATUS_UPGRADED diff --git a/toolkit/components/places/tests/migration/head_migration.js b/toolkit/components/places/tests/migration/head_migration.js index cba9b5adbdc6..a58aada16aca 100644 --- a/toolkit/components/places/tests/migration/head_migration.js +++ b/toolkit/components/places/tests/migration/head_migration.js @@ -13,8 +13,8 @@ // Put any other stuff relative to this test folder below. -const CURRENT_SCHEMA_VERSION = 75; -const FIRST_UPGRADABLE_SCHEMA_VERSION = 43; +const CURRENT_SCHEMA_VERSION = Ci.nsINavHistoryService.DATABASE_SCHEMA_VERSION; +const FIRST_UPGRADABLE_SCHEMA_VERSION = 52; async function assertAnnotationsRemoved(db, expectedAnnos) { for (let anno of expectedAnnos) { diff --git a/toolkit/components/places/tests/migration/places_v43.sqlite b/toolkit/components/places/tests/migration/places_v43.sqlite deleted file mode 100644 index 9210f215fa8df4475513add0dfe924465325da91..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1146880 zcmeI*d30R&eHi)~%wVt)1b0ZHEkTlHiRMmlwWG+~_eB&*iCzxg02qKH05jmsfCL~B zKhcTXXN!J~+_;H+(ib&x`kcnj($sB|rmTI_A>^P27C#heK?RU<* z_YMXN7bQI>u2cJSk9dFg``dq?d+(2z`e&Ya{6w)<=ou>d!RSxp=!q_}jUYha2FDsQ{|`OC+~e{KAG%fDVeQTm0_ z8^=B}wsQ1()QN)t0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF z5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk z1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+z_&!;`s*HO>3)2D`ufFUX|OOkR-W#Qe(7th z+Ltet%GKmLU#nG${S&pq?P@%@|LnoN=MMIqKXvr+^9Os5o;q;wsh+>Sm!8w7Zm!ky zNIY;~ad1OVJa*sQuu;~!>s|M^bRWJief{9vBjO8mM)xP10;^56Qn=9?P)70i_ z+|s@=rMVhCkHkZ)d-mRz?t{@B?!L_&qFEO5gM)>^Tg&d7ox%L`G}m#wxCPB_GjLpC zZ`|*?>&su;()~m<{El0PNS^J{e6==K9xM(OZ#Rp3Uu72Y!+J~W+e~I?WJ6C}@8s+# z>#n_~rTeiv+?DZsrBJHfI@i~}%0w2lxy|tP(hWV)V^ORX%cXUf*S2)ODH^`>)=?6X zTeDyDDuc%gNsHSI9k0ALHC|YEJ#$Y>_x{ZbAH++=YOP$Ex>Ag0RZZ^b+_;O1*4{Gq zqT>0Mjqw*1_dJpekkpE1ardjwVyIHCuO;5T7WH$_Uo(rjmUoy%T;7*VW!?4eyIQ(W zMi!6Ve!=yZK7N94Uw-#rGnHiPnQMNB`ONQY3w*A0M?CkZudkjPIH`8~t)gCZ*X(3& z+5GR&vN4@{@$3#Uvn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>m7@Do!<$~(%Zo;ZK(LU)`|n9L6jmP<)DcP+^1jdRv6 z$k-NV+_NBKYn*X+J>%f1OHc1Pf9hmu-_kha;?Tt5izEHTV^=D}opHwbfx_7N-olZA zQxikW;*2Lwofx}%?8wf;wI}zij5AIg*mY?4xxFVwcOBT?6=xjUeeB%SxwB7S9ynTE z9%mdpc6jH}t)=55j~{w`O`LIHtbfi_i+M{Yq!+TTV>*3GCm%?YmE8)}O z{|>(zekuI(@Xx}Jh4)8=4gv%S5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs z0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZ zfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&U zAn-q2pe375r|-%vP15e>CG|AZnWSr)+v{njBS}{`x7O24TavD7&ehXQOOme4HrLZk VHc6K^Ws-DRQ&V#`-PV@-{{dPvu`mDt diff --git a/toolkit/components/places/tests/migration/places_v52.sqlite b/toolkit/components/places/tests/migration/places_v52.sqlite new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/toolkit/components/places/tests/migration/test_current_from_v43.js b/toolkit/components/places/tests/migration/test_current_from_v43.js deleted file mode 100644 index 8dfe6e5f729f..000000000000 --- a/toolkit/components/places/tests/migration/test_current_from_v43.js +++ /dev/null @@ -1,253 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ */ - -"use strict"; - -const EXPECTED_REMAINING_ROOTS = [ - ...PlacesUtils.bookmarks.userContentRoots, - PlacesUtils.bookmarks.tagsGuid, -]; - -const EXPECTED_REMOVED_BOOKMARK_GUIDS = [ - // These first ones are the old left-pane folder queries - "SNLmwJH6GtW9", // Root Query - "r0dY_2_y4mlx", // History - "xGGhZK3b6GnW", // Downloads - "EJG6I1nKkQFQ", // Tags - "gSyHo5oNSUJV", // All Bookmarks - // These are simulated add-on injections that we expect to be removed. - "exaddon_____", - "exaddon1____", - "exaddon2____", - "exaddon3____", - "test________", -]; - -const EXPECTED_REMOVED_ANNOTATIONS = [ - "PlacesOrganizer/OrganizerFolder", - "PlacesOrganizer/OrganizerQuery", -]; - -const EXPECTED_REMOVED_PLACES_ENTRIES = ["exaddonh____", "exaddonh3___"]; -const EXPECTED_KEPT_PLACES_ENTRY = "exaddonh2___"; -const EXPECTED_REMOVED_KEYWORDS = ["exaddon", "exaddon2"]; - -async function assertItemIn(db, table, field, expectedItems) { - let rows = await db.execute(`SELECT ${field} from ${table}`); - - Assert.ok( - rows.length >= expectedItems.length, - "Should be at least the number of annotations we expect to be removed." - ); - - let fieldValues = rows.map(row => row.getResultByName(field)); - - for (let item of expectedItems) { - Assert.ok( - fieldValues.includes(item), - `${table} should have ${expectedItems}` - ); - } -} - -add_task(async function setup() { - await setupPlacesDatabase("places_v43.sqlite"); - - // Setup database contents to be migrated. - let path = PathUtils.join(PathUtils.profileDir, DB_FILENAME); - let db = await Sqlite.openConnection({ path }); - - let rows = await db.execute(`SELECT * FROM moz_bookmarks_deleted`); - Assert.equal(rows.length, 0, "Should be nothing in moz_bookmarks_deleted"); - - // Break roots parenting, to test for Bug 1472127. - await db.execute(`INSERT INTO moz_bookmarks (title, parent, position, guid) - VALUES ("test", 1, 0, "test________")`); - await db.execute(`UPDATE moz_bookmarks - SET parent = (SELECT id FROM moz_bookmarks WHERE guid = "test________") - WHERE guid = "menu________"`); - - await assertItemIn( - db, - "moz_anno_attributes", - "name", - EXPECTED_REMOVED_ANNOTATIONS - ); - await assertItemIn( - db, - "moz_bookmarks", - "guid", - EXPECTED_REMOVED_BOOKMARK_GUIDS - ); - await assertItemIn(db, "moz_keywords", "keyword", EXPECTED_REMOVED_KEYWORDS); - await assertItemIn(db, "moz_places", "guid", EXPECTED_REMOVED_PLACES_ENTRIES); - - await db.close(); -}); - -add_task(async function database_is_valid() { - // Accessing the database for the first time triggers migration. - Assert.equal( - PlacesUtils.history.databaseStatus, - PlacesUtils.history.DATABASE_STATUS_UPGRADED - ); - - let db = await PlacesUtils.promiseDBConnection(); - Assert.equal(await db.getSchemaVersion(), CURRENT_SCHEMA_VERSION); -}); - -add_task(async function test_roots_removed() { - let db = await PlacesUtils.promiseDBConnection(); - let rows = await db.execute( - ` - SELECT id FROM moz_bookmarks - WHERE guid = :guid - `, - { guid: PlacesUtils.bookmarks.rootGuid } - ); - Assert.equal(rows.length, 1, "Should have exactly one root row."); - let rootId = rows[0].getResultByName("id"); - - rows = await db.execute( - ` - SELECT guid FROM moz_bookmarks - WHERE parent = :rootId`, - { rootId } - ); - - Assert.equal( - rows.length, - EXPECTED_REMAINING_ROOTS.length, - "Should only have the built-in folder roots." - ); - - for (let row of rows) { - let guid = row.getResultByName("guid"); - Assert.ok( - EXPECTED_REMAINING_ROOTS.includes(guid), - `Should have only the expected guids remaining, unexpected guid: ${guid}` - ); - } - - // Check the reparented menu now. - rows = await db.execute( - ` - SELECT id, parent FROM moz_bookmarks - WHERE guid = :guid - `, - { guid: PlacesUtils.bookmarks.menuGuid } - ); - Assert.equal(rows.length, 1, "Should have found the menu root."); - Assert.equal( - rows[0].getResultByName("parent"), - await PlacesTestUtils.promiseItemId(PlacesUtils.bookmarks.rootGuid), - "Should have moved the menu back to the Places root." - ); -}); - -add_task(async function test_tombstones_added() { - let db = await PlacesUtils.promiseDBConnection(); - - let rows = await db.execute(` - SELECT guid FROM moz_bookmarks_deleted - `); - - for (let row of rows) { - let guid = row.getResultByName("guid"); - Assert.ok( - EXPECTED_REMOVED_BOOKMARK_GUIDS.includes(guid), - `Should have tombstoned the expected guids, unexpected guid: ${guid}` - ); - } - - Assert.equal( - rows.length, - EXPECTED_REMOVED_BOOKMARK_GUIDS.length, - "Should have removed all the expected bookmarks." - ); -}); - -add_task(async function test_annotations_removed() { - let db = await PlacesUtils.promiseDBConnection(); - - await assertAnnotationsRemoved(db, EXPECTED_REMOVED_ANNOTATIONS); -}); - -add_task(async function test_check_history_entries() { - let db = await PlacesUtils.promiseDBConnection(); - - for (let entry of EXPECTED_REMOVED_PLACES_ENTRIES) { - let rows = await db.execute(` - SELECT id FROM moz_places - WHERE guid = '${entry}'`); - - Assert.equal( - rows.length, - 0, - `Should have removed an orphaned history entry ${EXPECTED_REMOVED_PLACES_ENTRIES}.` - ); - } - - let rows = await db.execute( - ` - SELECT foreign_count FROM moz_places - WHERE guid = :guid - `, - { guid: EXPECTED_KEPT_PLACES_ENTRY } - ); - - Assert.equal( - rows.length, - 1, - `Should have kept visited history entry ${EXPECTED_KEPT_PLACES_ENTRY}` - ); - - let foreignCount = rows[0].getResultByName("foreign_count"); - Assert.equal( - foreignCount, - 0, - `Should have updated the foreign_count for ${EXPECTED_KEPT_PLACES_ENTRY}` - ); -}); - -add_task(async function test_check_keyword_removed() { - let db = await PlacesUtils.promiseDBConnection(); - - for (let keyword of EXPECTED_REMOVED_KEYWORDS) { - let rows = await db.execute( - ` - SELECT keyword FROM moz_keywords - WHERE keyword = :keyword - `, - { keyword } - ); - - Assert.equal( - rows.length, - 0, - `Should have removed the expected keyword: ${keyword}.` - ); - } -}); - -add_task(async function test_no_orphan_annotations() { - let db = await PlacesUtils.promiseDBConnection(); - - await assertNoOrphanAnnotations(db); -}); - -add_task(async function test_no_orphan_keywords() { - let db = await PlacesUtils.promiseDBConnection(); - - let rows = await db.execute(` - SELECT place_id FROM moz_keywords - WHERE place_id NOT IN (SELECT id from moz_places) - `); - - Assert.equal(rows.length, 0, `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`); -}); diff --git a/toolkit/components/places/tests/migration/test_current_from_v45.js b/toolkit/components/places/tests/migration/test_current_from_v45.js deleted file mode 100644 index af940d75d439..000000000000 --- a/toolkit/components/places/tests/migration/test_current_from_v45.js +++ /dev/null @@ -1,100 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ */ - -"use strict"; - -let gTags = [ - { - folder: 123456, - url: "place:folder=123456&type=7&queryType=1", - title: "tag1", - hash: "268505532566465", - }, - { - folder: 234567, - url: "place:folder=234567&type=7&queryType=1&somethingelse", - title: "tag2", - hash: "268506675127932", - }, - { - folder: 345678, - url: "place:type=7&folder=345678&queryType=1", - title: "tag3", - hash: "268506471927988", - }, - // This will point to an invalid folder id. - { - folder: 456789, - url: "place:type=7&folder=456789&queryType=1", - expectedUrl: - "place:type=7&invalidOldParentId=456789&queryType=1&excludeItems=1", - title: "invalid", - hash: "268505972797836", - }, -]; -gTags.forEach(t => (t.guid = t.title.padEnd(12, "_"))); - -add_task(async function setup() { - await setupPlacesDatabase("places_v43.sqlite"); - - // Setup database contents to be migrated. - let path = PathUtils.join(PathUtils.profileDir, DB_FILENAME); - let db = await Sqlite.openConnection({ path }); - - for (let tag of gTags) { - // We can reuse the same guid, it doesn't matter for this test. - await db.execute( - `INSERT INTO moz_places (url, guid, url_hash) - VALUES (:url, :guid, :hash) - `, - { url: tag.url, guid: tag.guid, hash: tag.hash } - ); - if (tag.title != "invalid") { - await db.execute( - `INSERT INTO moz_bookmarks (id, fk, guid, title) - VALUES (:id, (SELECT id FROM moz_places WHERE guid = :guid), :guid, :title) - `, - { id: tag.folder, guid: tag.guid, title: tag.title } - ); - } - } - - await db.close(); -}); - -add_task(async function database_is_valid() { - // Accessing the database for the first time triggers migration. - Assert.equal( - PlacesUtils.history.databaseStatus, - PlacesUtils.history.DATABASE_STATUS_UPGRADED - ); - - let db = await PlacesUtils.promiseDBConnection(); - Assert.equal(await db.getSchemaVersion(), CURRENT_SCHEMA_VERSION); -}); - -add_task(async function test_queries_converted() { - for (let tag of gTags) { - let url = - tag.title == "invalid" ? tag.expectedUrl : "place:tag=" + tag.title; - let page = await PlacesUtils.history.fetch(tag.guid); - Assert.equal(page.url.href, url); - } -}); - -add_task(async function test_sync_fields() { - let db = await PlacesUtils.promiseDBConnection(); - for (let tag of gTags) { - if (tag.title != "invalid") { - let rows = await db.execute( - ` - SELECT syncChangeCounter - FROM moz_bookmarks - WHERE guid = :guid - `, - { guid: tag.guid } - ); - Assert.equal(rows[0].getResultByIndex(0), 2); - } - } -}); diff --git a/toolkit/components/places/tests/migration/test_current_from_v46.js b/toolkit/components/places/tests/migration/test_current_from_v46.js deleted file mode 100644 index a613a3027e8c..000000000000 --- a/toolkit/components/places/tests/migration/test_current_from_v46.js +++ /dev/null @@ -1,52 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ */ - -"use strict"; - -let guid = "null".padEnd(12, "_"); - -add_task(async function setup() { - await setupPlacesDatabase("places_v43.sqlite"); - - // Setup database contents to be migrated. - let path = PathUtils.join(PathUtils.profileDir, DB_FILENAME); - let db = await Sqlite.openConnection({ path }); - // We can reuse the same guid, it doesn't matter for this test. - - await db.execute( - `INSERT INTO moz_places (url, guid, url_hash) - VALUES (NULL, :guid, "123456")`, - { guid } - ); - await db.execute( - `INSERT INTO moz_bookmarks (fk, guid) - VALUES ((SELECT id FROM moz_places WHERE guid = :guid), :guid) - `, - { guid } - ); - await db.close(); -}); - -add_task(async function database_is_valid() { - // Accessing the database for the first time triggers migration. - Assert.equal( - PlacesUtils.history.databaseStatus, - PlacesUtils.history.DATABASE_STATUS_UPGRADED - ); - - let db = await PlacesUtils.promiseDBConnection(); - Assert.equal(await db.getSchemaVersion(), CURRENT_SCHEMA_VERSION); - - let page = await PlacesUtils.history.fetch(guid); - Assert.equal(page.url.href, "place:excludeItems=1"); - - let rows = await db.execute( - ` - SELECT syncChangeCounter - FROM moz_bookmarks - WHERE guid = :guid - `, - { guid } - ); - Assert.equal(rows[0].getResultByIndex(0), 2); -}); diff --git a/toolkit/components/places/tests/migration/test_current_from_v47.js b/toolkit/components/places/tests/migration/test_current_from_v47.js deleted file mode 100644 index b3d5f47211c6..000000000000 --- a/toolkit/components/places/tests/migration/test_current_from_v47.js +++ /dev/null @@ -1,128 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ */ - -"use strict"; - -add_task(async function setup() { - await setupPlacesDatabase("places_v43.sqlite"); -}); - -// Accessing the database for the first time should trigger migration, and the -// schema version should be updated. -add_task(async function database_is_valid() { - Assert.equal( - PlacesUtils.history.databaseStatus, - PlacesUtils.history.DATABASE_STATUS_UPGRADED - ); - - let db = await PlacesUtils.promiseDBConnection(); - Assert.equal(await db.getSchemaVersion(), CURRENT_SCHEMA_VERSION); - - // Now wait for moz_origins.frecency to be populated before continuing with - // other test tasks. - await TestUtils.waitForCondition( - () => { - return !Services.prefs.getBoolPref( - "places.database.migrateV52OriginFrecencies", - false - ); - }, - "Waiting for v52 origin frecencies to be migrated", - 100, - 3000 - ); -}); - -// moz_origins should be populated. -add_task(async function test_origins() { - let db = await PlacesUtils.promiseDBConnection(); - - // Collect origins. - let rows = await db.execute(` - SELECT id, prefix, host, frecency - FROM moz_origins - ORDER BY id ASC; - `); - Assert.notEqual(rows.length, 0); - let origins = rows.map(r => ({ - id: r.getResultByName("id"), - prefix: r.getResultByName("prefix"), - host: r.getResultByName("host"), - frecency: r.getResultByName("frecency"), - })); - - // Get moz_places. - rows = await db.execute(` - SELECT get_prefix(url) AS prefix, get_host_and_port(url) AS host, - origin_id, frecency - FROM moz_places; - `); - Assert.notEqual(rows.length, 0); - - let seenOriginIDs = []; - let frecenciesByOriginID = {}; - - // Make sure moz_places.origin_id refers to the right origins. - for (let row of rows) { - let originID = row.getResultByName("origin_id"); - let origin = origins.find(o => o.id == originID); - Assert.ok(origin); - Assert.equal(origin.prefix, row.getResultByName("prefix")); - Assert.equal(origin.host, row.getResultByName("host")); - - seenOriginIDs.push(originID); - - let frecency = row.getResultByName("frecency"); - frecenciesByOriginID[originID] = frecenciesByOriginID[originID] || 0; - frecenciesByOriginID[originID] += frecency; - } - - for (let origin of origins) { - // Make sure each origin corresponds to at least one moz_place. - Assert.ok(seenOriginIDs.includes(origin.id)); - - // moz_origins.frecency should be the sum of frecencies of all moz_places - // with the origin. - Assert.equal(origin.frecency, frecenciesByOriginID[origin.id]); - } - - // Make sure moz_hosts was emptied. - rows = await db.execute(` - SELECT * - FROM moz_hosts; - `); - Assert.equal(rows.length, 0); -}); - -// Frecency stats should have been collected. -add_task(async function test_frecency_stats() { - let db = await PlacesUtils.promiseDBConnection(); - - // Collect positive frecencies from moz_origins. - let rows = await db.execute(` - SELECT frecency FROM moz_origins WHERE frecency > 0 - `); - Assert.notEqual(rows.length, 0); - let frecencies = rows.map(r => r.getResultByName("frecency")); - - // Collect stats. - rows = await db.execute(` - SELECT - (SELECT value FROM moz_meta WHERE key = "origin_frecency_count"), - (SELECT value FROM moz_meta WHERE key = "origin_frecency_sum"), - (SELECT value FROM moz_meta WHERE key = "origin_frecency_sum_of_squares") - `); - let count = rows[0].getResultByIndex(0); - let sum = rows[0].getResultByIndex(1); - let squares = rows[0].getResultByIndex(2); - - Assert.equal(count, frecencies.length); - Assert.equal( - sum, - frecencies.reduce((memo, f) => memo + f, 0) - ); - Assert.equal( - squares, - frecencies.reduce((memo, f) => memo + f * f, 0) - ); -}); diff --git a/toolkit/components/places/tests/migration/test_current_from_v48.js b/toolkit/components/places/tests/migration/test_current_from_v48.js deleted file mode 100644 index f2c7c683ed66..000000000000 --- a/toolkit/components/places/tests/migration/test_current_from_v48.js +++ /dev/null @@ -1,190 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ */ - -"use strict"; - -const gCreatedParentGuid = "m47___FOLDER"; - -const gTestItems = [ - { - // Folder shortcuts to built-in folders. - guid: "m47_____ROOT", - url: "place:folder=PLACES_ROOT", - targetParentGuid: "rootGuid", - }, - { - guid: "m47_____MENU", - url: "place:folder=BOOKMARKS_MENU", - targetParentGuid: "menuGuid", - }, - { - guid: "m47_____TAGS", - url: "place:folder=TAGS", - targetParentGuid: "tagsGuid", - }, - { - guid: "m47____OTHER", - url: "place:folder=UNFILED_BOOKMARKS", - targetParentGuid: "unfiledGuid", - }, - { - guid: "m47__TOOLBAR", - url: "place:folder=TOOLBAR", - targetParentGuid: "toolbarGuid", - }, - { - guid: "m47___MOBILE", - url: "place:folder=MOBILE_BOOKMARKS", - targetParentGuid: "mobileGuid", - }, - { - // Folder shortcut to using id. - guid: "m47_______ID", - url: "place:folder=%id%", - expectedUrl: "place:parent=%guid%", - }, - { - // Folder shortcut to multiple folders. - guid: "m47____MULTI", - url: "place:folder=TOOLBAR&folder=%id%&sort=1", - expectedUrl: "place:parent=%toolbarGuid%&parent=%guid%&sort=1", - }, - { - // Folder shortcut to non-existent folder. - guid: "m47______NON", - url: "place:folder=454554545", - expectedUrl: "place:invalidOldParentId=454554545&excludeItems=1", - }, -]; - -add_task(async function setup() { - await setupPlacesDatabase("places_v43.sqlite"); - - // Setup database contents to be migrated. - let path = PathUtils.join(PathUtils.profileDir, DB_FILENAME); - let db = await Sqlite.openConnection({ path }); - - let rows = await db.execute( - `SELECT id FROM moz_bookmarks - WHERE guid = :guid`, - { guid: PlacesUtils.bookmarks.unfiledGuid } - ); - - let unfiledId = rows[0].getResultByName("id"); - - // Insert a test folder. - await db.execute( - `INSERT INTO moz_bookmarks (guid, title, parent) - VALUES (:guid, "Folder", :parent)`, - { guid: gCreatedParentGuid, parent: unfiledId } - ); - - rows = await db.execute( - `SELECT id FROM moz_bookmarks - WHERE guid = :guid`, - { guid: gCreatedParentGuid } - ); - - let createdFolderId = rows[0].getResultByName("id"); - - for (let item of gTestItems) { - item.url = item.url.replace("%id%", createdFolderId); - - // We can reuse the same guid, it doesn't matter for this test. - await db.execute( - `INSERT INTO moz_places (url, guid, url_hash) - VALUES (:url, :guid, :hash) - `, - { - url: item.url, - guid: item.guid, - hash: PlacesUtils.history.hashURL(item.url), - } - ); - await db.execute( - `INSERT INTO moz_bookmarks (id, fk, guid, title, parent) - VALUES (:id, (SELECT id FROM moz_places WHERE guid = :guid), - :guid, :title, - (SELECT id FROM moz_bookmarks WHERE guid = :parentGuid)) - `, - { - id: item.folder, - guid: item.guid, - parentGuid: PlacesUtils.bookmarks.unfiledGuid, - title: item.guid, - } - ); - } - - await db.close(); -}); - -add_task(async function database_is_valid() { - // Accessing the database for the first time triggers migration. - Assert.equal( - PlacesUtils.history.databaseStatus, - PlacesUtils.history.DATABASE_STATUS_UPGRADED - ); - - let db = await PlacesUtils.promiseDBConnection(); - Assert.equal(await db.getSchemaVersion(), CURRENT_SCHEMA_VERSION); -}); - -add_task(async function test_correct_folder_queries() { - for (let item of gTestItems) { - let bm = await PlacesUtils.bookmarks.fetch(item.guid); - - if (item.targetParentGuid) { - Assert.equal( - bm.url, - `place:parent=${PlacesUtils.bookmarks[item.targetParentGuid]}`, - `Should have updated the URL for ${item.guid}` - ); - } else { - let expected = item.expectedUrl - .replace("%guid%", gCreatedParentGuid) - .replace("%toolbarGuid%", PlacesUtils.bookmarks.toolbarGuid); - - Assert.equal( - bm.url, - expected, - `Should have updated the URL for ${item.guid}` - ); - } - } -}); - -add_task(async function test_hashes_valid() { - let db = await PlacesUtils.promiseDBConnection(); - // Ensure all the hashes in moz_places are valid. - let rows = await db.execute(`SELECT url, url_hash FROM moz_places`); - - for (let row of rows) { - let url = row.getResultByName("url"); - let url_hash = row.getResultByName("url_hash"); - Assert.equal( - url_hash, - PlacesUtils.history.hashURL(url), - `url hash should be correct for ${url}` - ); - } -}); - -add_task(async function test_sync_counters_updated() { - let db = await PlacesUtils.promiseDBConnection(); - - for (let test of gTestItems) { - let rows = await db.execute( - `SELECT syncChangeCounter FROM moz_bookmarks - WHERE guid = :guid`, - { guid: test.guid } - ); - - Assert.equal(rows.length, 1, `Should only be one record for ${test.guid}`); - Assert.equal( - rows[0].getResultByName("syncChangeCounter"), - 2, - `Should have bumped the syncChangeCounter for ${test.guid}` - ); - } -}); diff --git a/toolkit/components/places/tests/migration/test_current_from_v50.js b/toolkit/components/places/tests/migration/test_current_from_v50.js deleted file mode 100644 index af181091c0fe..000000000000 --- a/toolkit/components/places/tests/migration/test_current_from_v50.js +++ /dev/null @@ -1,209 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ */ - -"use strict"; - -const BASE_GUID = "null".padEnd(11, "_"); -const LAST_USED_ANNO = "bookmarkPropertiesDialog/folderLastUsed"; -const LAST_USED_META_DATA = "places/bookmarks/edit/lastusedfolder"; - -let expectedGuids = []; - -async function adjustIndices(db, itemGuid) { - await db.execute( - ` - UPDATE moz_bookmarks SET - position = position - 1 - WHERE parent = (SELECT parent FROM moz_bookmarks - WHERE guid = :itemGuid) AND - position >= (SELECT position FROM moz_bookmarks - WHERE guid = :itemGuid)`, - { itemGuid } - ); -} - -async function fetchChildInfos(db, parentGuid) { - let rows = await db.execute( - ` - SELECT b.guid, b.position, b.syncChangeCounter - FROM moz_bookmarks b - JOIN moz_bookmarks p ON p.id = b.parent - WHERE p.guid = :parentGuid - ORDER BY b.position`, - { parentGuid } - ); - return rows.map(row => ({ - guid: row.getResultByName("guid"), - position: row.getResultByName("position"), - syncChangeCounter: row.getResultByName("syncChangeCounter"), - })); -} - -add_task(async function setup() { - await setupPlacesDatabase("places_v43.sqlite"); - - // Setup database contents to be migrated. - let path = PathUtils.join(PathUtils.profileDir, DB_FILENAME); - let db = await Sqlite.openConnection({ path }); - // We can reuse the same guid, it doesn't matter for this test. - await db.execute( - `INSERT INTO moz_anno_attributes (name) - VALUES (:last_used_anno)`, - { last_used_anno: LAST_USED_ANNO } - ); - - for (let i = 0; i < 3; i++) { - let guid = `${BASE_GUID}${i}`; - await db.execute( - `INSERT INTO moz_bookmarks (guid, type) - VALUES (:guid, :type) - `, - { guid, type: PlacesUtils.bookmarks.TYPE_FOLDER } - ); - await db.execute( - `INSERT INTO moz_items_annos (item_id, anno_attribute_id, content) - VALUES ((SELECT id FROM moz_bookmarks WHERE guid = :guid), - (SELECT id FROM moz_anno_attributes WHERE name = :last_used_anno), - :content)`, - { - guid, - content: new Date(1517318477569) - (3 - i) * 60 * 60 * 1000, - last_used_anno: LAST_USED_ANNO, - } - ); - expectedGuids.unshift(guid); - } - - info("Move menu into unfiled"); - await adjustIndices(db, "menu________"); - await db.execute( - ` - UPDATE moz_bookmarks SET - parent = (SELECT id FROM moz_bookmarks WHERE guid = :newParentGuid), - position = IFNULL((SELECT MAX(position) + 1 FROM moz_bookmarks - WHERE guid = :newParentGuid), 0) - WHERE guid = :itemGuid`, - { newParentGuid: "unfiled_____", itemGuid: "menu________" } - ); - - info("Move toolbar into mobile"); - let mobileChildren = [ - "bookmarkAAAA", - "bookmarkBBBB", - "toolbar_____", - "bookmarkCCCC", - "bookmarkDDDD", - ]; - await adjustIndices(db, "toolbar_____"); - for (let position = 0; position < mobileChildren.length; position++) { - await db.execute( - ` - INSERT INTO moz_bookmarks(guid, parent, position) - VALUES(:guid, (SELECT id FROM moz_bookmarks WHERE guid = 'mobile______'), - :position) - ON CONFLICT(guid) DO UPDATE SET - parent = excluded.parent, - position = excluded.position`, - { guid: mobileChildren[position], position } - ); - } - - info("Reset Sync change counters"); - await db.execute(`UPDATE moz_bookmarks SET syncChangeCounter = 0`); - - await db.close(); -}); - -add_task(async function database_is_valid() { - // Accessing the database for the first time triggers migration. - Assert.equal( - PlacesUtils.history.databaseStatus, - PlacesUtils.history.DATABASE_STATUS_UPGRADED - ); - - let db = await PlacesUtils.promiseDBConnection(); - Assert.equal(await db.getSchemaVersion(), CURRENT_SCHEMA_VERSION); -}); - -add_task(async function test_folders_migrated() { - let metaData = await PlacesUtils.metadata.get(LAST_USED_META_DATA); - - Assert.deepEqual(JSON.parse(metaData), expectedGuids); -}); - -add_task(async function test_annotations_removed() { - let db = await PlacesUtils.promiseDBConnection(); - - await assertAnnotationsRemoved(db, [LAST_USED_ANNO]); -}); - -add_task(async function test_no_orphan_annotations() { - let db = await PlacesUtils.promiseDBConnection(); - - await assertNoOrphanAnnotations(db); -}); - -add_task(async function test_roots_fixed() { - let db = await PlacesUtils.promiseDBConnection(); - - let expectedRootInfos = [ - { - guid: PlacesUtils.bookmarks.tagsGuid, - position: 0, - syncChangeCounter: 0, - }, - { - guid: PlacesUtils.bookmarks.unfiledGuid, - position: 1, - syncChangeCounter: 1, - }, - { - guid: PlacesUtils.bookmarks.mobileGuid, - position: 2, - syncChangeCounter: 1, - }, - { - guid: PlacesUtils.bookmarks.menuGuid, - position: 3, - syncChangeCounter: 1, - }, - { - guid: PlacesUtils.bookmarks.toolbarGuid, - position: 4, - syncChangeCounter: 1, - }, - ]; - Assert.deepEqual( - expectedRootInfos, - await fetchChildInfos(db, PlacesUtils.bookmarks.rootGuid), - "All roots should be reparented to the Places root" - ); - - let expectedMobileInfos = [ - { - guid: "bookmarkAAAA", - position: 0, - syncChangeCounter: 0, - }, - { - guid: "bookmarkBBBB", - position: 1, - syncChangeCounter: 0, - }, - { - guid: "bookmarkCCCC", - position: 2, - syncChangeCounter: 0, - }, - { - guid: "bookmarkDDDD", - position: 3, - syncChangeCounter: 0, - }, - ]; - Assert.deepEqual( - expectedMobileInfos, - await fetchChildInfos(db, PlacesUtils.bookmarks.mobileGuid), - "Should fix misparented root sibling positions" - ); -}); diff --git a/toolkit/components/places/tests/migration/test_current_from_v53.js b/toolkit/components/places/tests/migration/test_current_from_v53.js index f872dea5d5ca..ce7b31c8dfd4 100644 --- a/toolkit/components/places/tests/migration/test_current_from_v53.js +++ b/toolkit/components/places/tests/migration/test_current_from_v53.js @@ -1,6 +1,6 @@ add_task(async function setup() { // Since this migration doesn't affect places.sqlite, we can reuse v43. - await setupPlacesDatabase("places_v43.sqlite"); + await setupPlacesDatabase("places_v52.sqlite"); await setupPlacesDatabase("favicons_v41.sqlite", "favicons.sqlite"); }); diff --git a/toolkit/components/places/tests/migration/xpcshell.ini b/toolkit/components/places/tests/migration/xpcshell.ini index 914502af11be..4d8b74ec1887 100644 --- a/toolkit/components/places/tests/migration/xpcshell.ini +++ b/toolkit/components/places/tests/migration/xpcshell.ini @@ -6,7 +6,7 @@ skip-if = condprof # Not worth running conditioned profiles on these migration support-files = favicons_v41.sqlite places_outdated.sqlite - places_v43.sqlite + places_v52.sqlite places_v54.sqlite places_v66.sqlite places_v68.sqlite @@ -18,12 +18,6 @@ support-files = [test_current_from_downgraded.js] [test_current_from_outdated.js] -[test_current_from_v43.js] -[test_current_from_v45.js] -[test_current_from_v46.js] -[test_current_from_v47.js] -[test_current_from_v48.js] -[test_current_from_v50.js] [test_current_from_v53.js] [test_current_from_v54.js] [test_current_from_v66.js]