Bug 1549912 - Support downgrade versioning of permissions database, r=mayhemer

Differential Revision: https://phabricator.services.mozilla.com/D31192

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Andrea Marchesini 2019-05-16 19:51:34 +00:00
parent fe70dc7ab6
commit 6cd7a6d9dd
2 changed files with 3 additions and 53 deletions

View File

@ -1572,58 +1572,8 @@ nsresult nsPermissionManager::InitDB(bool aRemoveFile) {
// fall through to the next upgrade
MOZ_FALLTHROUGH;
// Version 10 removes appId from moz_hosts. SQLite doesn't support the
// dropping of columns from existing tables. We need to create a temporary
// table, copy the data, drop the old table, rename the new one.
case 9: {
rv = mDBConn->BeginTransaction();
NS_ENSURE_SUCCESS(rv, rv);
bool tableExists = false;
mDBConn->TableExists(NS_LITERAL_CSTRING("moz_hosts_v9"), &tableExists);
if (tableExists) {
NS_WARNING(
"The temporary database moz_hosts_v9 already exists, dropping "
"it.");
rv = mDBConn->ExecuteSimpleSQL(
NS_LITERAL_CSTRING("DROP TABLE moz_hosts_v9"));
NS_ENSURE_SUCCESS(rv, rv);
}
rv = mDBConn->ExecuteSimpleSQL(
NS_LITERAL_CSTRING("CREATE TABLE moz_hosts_v9 ("
" id INTEGER PRIMARY KEY"
",host TEXT"
",type TEXT"
",permission INTEGER"
",expireType INTEGER"
",expireTime INTEGER"
",modificationTime INTEGER"
",isInBrowserElement INTEGER"
")"));
NS_ENSURE_SUCCESS(rv, rv);
rv = mDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
"INSERT INTO moz_hosts_v9 "
"(id, host, type, permission, expireType, "
"expireTime, modificationTime, isInBrowserElement) "
"SELECT id, host, type, permission, expireType, expireTime, "
"modificationTime, isInBrowserElement FROM moz_hosts WHERE appId = "
"0"));
NS_ENSURE_SUCCESS(rv, rv);
rv = mDBConn->ExecuteSimpleSQL(
NS_LITERAL_CSTRING("DROP TABLE moz_hosts"));
NS_ENSURE_SUCCESS(rv, rv);
rv = mDBConn->ExecuteSimpleSQL(
NS_LITERAL_CSTRING("ALTER TABLE moz_hosts_v9 RENAME TO moz_hosts"));
NS_ENSURE_SUCCESS(rv, rv);
rv = mDBConn->SetSchemaVersion(10);
NS_ENSURE_SUCCESS(rv, rv);
rv = mDBConn->CommitTransaction();
rv = mDBConn->SetSchemaVersion(HOSTS_SCHEMA_VERSION);
NS_ENSURE_SUCCESS(rv, rv);
}

View File

@ -21,7 +21,7 @@ add_task(async function test() {
let db = Services.storage.openDatabase(GetPermissionsFile(profile));
db.schemaVersion = 9;
db.executeSimpleSQL("DROP TABLE moz_perms");
db.executeSimpleSQL("DROP TABLE moz_hosts");
db.executeSimpleSQL("DROP TABLE IF EXISTS moz_hosts");
db.executeSimpleSQL(
"CREATE TABLE moz_perms (" +
@ -199,7 +199,7 @@ add_task(async function test() {
let mozHostsCount = db.createStatement("SELECT count(*) FROM moz_hosts");
try {
mozHostsCount.executeStep();
Assert.equal(mozHostsCount.getInt64(0), 1);
Assert.equal(mozHostsCount.getInt64(0), 3);
} finally {
mozHostsCount.finalize();
}