Bug 1431149 - Add an optional schema name argument to `OpenedConnection#{get, set}SchemaVersion`. r=mak
☠☠ backed out by f8230d6dd54f ☠ ☠
authorKit Cambridge <kit@yakshaving.ninja>
Wed, 17 Jan 2018 09:13:47 -0800
changeset 451685 410a941bdce8c11ec1da55d6cc541b93a93dda5c
parent 451684 d97649d30062fb55af2e8de3631a854afa52ab94
child 451686 7ed62b395dc2b4c0f50cb1d97abf9ddb8d10e86f
push id8560
push userryanvm@gmail.com
push dateFri, 19 Jan 2018 16:34:00 +0000
treeherdermozilla-beta@4c9965a3b8a0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs1431149
milestone59.0a1
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
Bug 1431149 - Add an optional schema name argument to `OpenedConnection#{get, set}SchemaVersion`. r=mak MozReview-Commit-ID: 8Uk1Vuqc1lc
toolkit/modules/Sqlite.jsm
toolkit/modules/tests/xpcshell/test_sqlite.js
--- a/toolkit/modules/Sqlite.jsm
+++ b/toolkit/modules/Sqlite.jsm
@@ -1166,34 +1166,34 @@ OpenedConnection.prototype = Object.free
 
   /**
    * The integer schema version of the database.
    *
    * This is 0 if not schema version has been set.
    *
    * @return Promise<int>
    */
-  getSchemaVersion() {
-    return this.execute("PRAGMA user_version").then(
+  getSchemaVersion(schemaName = "main") {
+    return this.execute(`PRAGMA ${schemaName}.user_version`).then(
       function onSuccess(result) {
         if (result == null) {
           return 0;
         }
         return JSON.stringify(result[0].getInt32(0));
       }
     );
   },
 
-  setSchemaVersion(value) {
+  setSchemaVersion(value, schemaName = "main") {
     if (!Number.isInteger(value)) {
       // Guarding against accidental SQLi
       throw new TypeError("Schema version must be an integer. Got " + value);
     }
     this._connectionData.ensureOpen();
-    return this.execute("PRAGMA user_version = " + value);
+    return this.execute(`PRAGMA ${schemaName}.user_version = ${value}`);
   },
 
   /**
    * Close the database connection.
    *
    * This must be performed when you are finished with the database.
    *
    * Closing the database connection has the side effect of forcefully
--- a/toolkit/modules/tests/xpcshell/test_sqlite.js
+++ b/toolkit/modules/tests/xpcshell/test_sqlite.js
@@ -127,16 +127,35 @@ add_task(async function test_schema_vers
       success = true;
     }
     Assert.ok(success);
 
     version = await db.getSchemaVersion();
     Assert.equal(version, 14);
   }
 
+  await db.execute("ATTACH :memory AS attached");
+
+  let attachedVersion = await db.getSchemaVersion("attached");
+  Assert.equal(attachedVersion, 0,
+    "Should return 0 for initial attached schema version");
+
+  await db.setSchemaVersion(3, "attached");
+  attachedVersion = await db.getSchemaVersion("attached");
+  Assert.equal(attachedVersion, 3, "Should set attached schema version");
+
+  version = await db.getSchemaVersion();
+  Assert.equal(version, 14,
+    "Setting attached schema version should not change main schema version");
+
+  await db.setSchemaVersion(15);
+  attachedVersion = await db.getSchemaVersion("attached");
+  Assert.equal(attachedVersion, 3,
+    "Setting main schema version should not change attached schema version");
+
   await db.close();
 });
 
 add_task(async function test_simple_insert() {
   let c = await getDummyDatabase("simple_insert");
 
   let result = await c.execute("INSERT INTO dirs VALUES (NULL, 'foo')");
   Assert.ok(Array.isArray(result));