Backed out changeset f8dfee6dc6e5 (bug 1549912) for xpcshell failure on test_permmanager_migrate_9-10.js CLOSE TREE.
authorOana Pop Rus <opoprus@mozilla.com>
Thu, 16 May 2019 22:04:19 +0300
changeset 474217 34287cc2fba86afb3147fb744e3e29095db249bf
parent 474216 3200f7d369342c9c42dce3088211631deb0f52fb
child 474218 2c5b7adbd1b03ca6e2fb36dbe52dba5633a66973
push id36027
push usershindli@mozilla.com
push dateFri, 17 May 2019 16:24:38 +0000
treeherdermozilla-central@c94c54aff466 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1549912
milestone68.0a1
backs outf8dfee6dc6e57a2a27978313a0409db058a08255
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Backed out changeset f8dfee6dc6e5 (bug 1549912) for xpcshell failure on test_permmanager_migrate_9-10.js CLOSE TREE.
extensions/permissions/nsPermissionManager.cpp
--- a/extensions/permissions/nsPermissionManager.cpp
+++ b/extensions/permissions/nsPermissionManager.cpp
@@ -1567,18 +1567,68 @@ nsresult nsPermissionManager::InitDB(boo
 
         rv = mDBConn->SetSchemaVersion(9);
         NS_ENSURE_SUCCESS(rv, rv);
       }
 
         // 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->SetSchemaVersion(HOSTS_SCHEMA_VERSION);
+        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();
         NS_ENSURE_SUCCESS(rv, rv);
       }
 
         // fall through to the next upgrade
         MOZ_FALLTHROUGH;
 
       // current version.
       case HOSTS_SCHEMA_VERSION: