Bug 1352502 - Part 1. Add description and preview_image_url to Places. r=mak

MozReview-Commit-ID: 4dvVboTm4kf

--HG--
extra : rebase_source : 8e5a0ebc9c9e4930b2a0f013c47c7018deb6ad54
This commit is contained in:
Nan Jiang 2017-05-23 14:54:13 -04:00
parent bdae7d6f5b
commit eb809f32a5
7 changed files with 80 additions and 2 deletions

View File

@ -1101,6 +1101,12 @@ Database::InitSchema(bool* aDatabaseMigrated)
// Firefox 55 uses schema version 37.
if (currentSchemaVersion < 38) {
rv = MigrateV38Up();
NS_ENSURE_SUCCESS(rv, rv);
}
// Firefox 56 uses schema version 38.
// Schema Upgrades must add migration code here.
rv = UpdateBookmarkRootTitles();
@ -2293,6 +2299,30 @@ Database::MigrateV37Up() {
return NS_OK;
}
nsresult
Database::MigrateV38Up()
{
MOZ_ASSERT(NS_IsMainThread());
nsCOMPtr<mozIStorageStatement> stmt;
nsresult rv = mMainConn->CreateStatement(NS_LITERAL_CSTRING(
"SELECT description, preview_image_url FROM moz_places"
), getter_AddRefs(stmt));
if (NS_FAILED(rv)) {
rv = mMainConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
"ALTER TABLE moz_places ADD COLUMN description TEXT"
));
NS_ENSURE_SUCCESS(rv, rv);
rv = mMainConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
"ALTER TABLE moz_places ADD COLUMN preview_image_url TEXT"
));
NS_ENSURE_SUCCESS(rv, rv);
}
return NS_OK;
}
nsresult
Database::GetItemsWithAnno(const nsACString& aAnnoName, int32_t aItemType,
nsTArray<int64_t>& aItemIds)

View File

@ -18,7 +18,7 @@
// This is the schema version. Update it at any schema change and add a
// corresponding migrateVxx method below.
#define DATABASE_SCHEMA_VERSION 37
#define DATABASE_SCHEMA_VERSION 38
// Fired after Places inited.
#define TOPIC_PLACES_INIT_COMPLETE "places-init-complete"
@ -298,6 +298,7 @@ protected:
nsresult MigrateV35Up();
nsresult MigrateV36Up();
nsresult MigrateV37Up();
nsresult MigrateV38Up();
nsresult UpdateBookmarkRootTitles();

View File

@ -22,6 +22,8 @@
", guid TEXT" \
", foreign_count INTEGER DEFAULT 0 NOT NULL" \
", url_hash INTEGER DEFAULT 0 NOT NULL " \
", description TEXT" \
", preview_image_url TEXT" \
")" \
)

View File

@ -6,7 +6,7 @@
// It is expected that the test files importing this file define Cu etc.
/* global Cu, Ci, Cc, Cr */
const CURRENT_SCHEMA_VERSION = 37;
const CURRENT_SCHEMA_VERSION = 38;
const FIRST_UPGRADABLE_SCHEMA_VERSION = 11;
const NS_APP_USER_PROFILE_50_DIR = "ProfD";

View File

@ -0,0 +1,43 @@
add_task(function* setup() {
yield setupPlacesDatabase("places_v38.sqlite");
});
add_task(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 = yield PlacesUtils.promiseDBConnection();
Assert.equal((yield db.getSchemaVersion()), CURRENT_SCHEMA_VERSION);
});
add_task(function* test_new_fields() {
let path = OS.Path.join(OS.Constants.Path.profileDir, DB_FILENAME);
let db = yield Sqlite.openConnection({ path });
// Manually update these two fields for a places record.
yield db.execute(`
UPDATE moz_places
SET description = :description, preview_image_url = :previewImageURL
WHERE id = 1`, { description: "Page description",
previewImageURL: "https://example.com/img.png" });
let rows = yield db.execute(`SELECT description FROM moz_places
WHERE description IS NOT NULL
AND preview_image_url IS NOT NULL`);
Assert.equal(rows.length, 1,
"should fetch one record with not null description and preview_image_url");
// Reset them to the default value
yield db.execute(`
UPDATE moz_places
SET description = NULL,
preview_image_url = NULL
WHERE id = 1`);
rows = yield db.execute(`SELECT description FROM moz_places
WHERE description IS NOT NULL
AND preview_image_url IS NOT NULL`);
Assert.equal(rows.length, 0,
"should fetch 0 record with not null description and preview_image_url");
yield db.close();
});

View File

@ -23,6 +23,7 @@ support-files =
places_v35.sqlite
places_v36.sqlite
places_v37.sqlite
places_v38.sqlite
[test_current_from_downgraded.js]
[test_current_from_v6.js]
@ -37,3 +38,4 @@ support-files =
[test_current_from_v34_no_roots.js]
[test_current_from_v35.js]
[test_current_from_v36.js]
[test_current_from_v38.js]