Bug 960741 - Messages app fails to upgrade database (JS exception in upgradeSchema14) after updating from 1.2 to 1.3. r=gene, a=1.3+
authorBevis Tseng <btseng@mozilla.com>
Fri, 17 Jan 2014 14:00:22 +0800
changeset 175924 2d9d1d3878544972881c6f4df3f59dad1a7662be
parent 175923 164d5ef28143b2e344678818f8ff0682e254eab5
child 175925 5fb1fa58180a0dc486fcb54b20d526659539b1a0
push id445
push userffxbld
push dateMon, 10 Mar 2014 22:05:19 +0000
treeherdermozilla-release@dc38b741b04e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgene, 1
bugs960741
milestone28.0a2
Bug 960741 - Messages app fails to upgrade database (JS exception in upgradeSchema14) after updating from 1.2 to 1.3. r=gene, a=1.3+
dom/mobilemessage/src/gonk/MobileMessageDatabaseService.js
--- a/dom/mobilemessage/src/gonk/MobileMessageDatabaseService.js
+++ b/dom/mobilemessage/src/gonk/MobileMessageDatabaseService.js
@@ -232,17 +232,28 @@ MobileMessageDatabaseService.prototype =
             self.upgradeSchema11(event.target.transaction, next);
             break;
           case 12:
             if (DEBUG) debug("Upgrade to version 13. Replaced deliveryStatus by deliveryInfo.");
             self.upgradeSchema12(event.target.transaction, next);
             break;
           case 13:
             if (DEBUG) debug("Upgrade to version 14. Fix the wrong participants.");
-            self.upgradeSchema13(event.target.transaction, next);
+            // A workaround to check if we need to re-upgrade the DB schema 12. We missed this
+            // because we didn't properly uplift that logic to b2g_v1.2 and errors could happen
+            // when migrating b2g_v1.2 to b2g_v1.3. Please see Bug 960741 for details.
+            self.needReUpgradeSchema12(event.target.transaction, function(isNeeded) {
+              if (isNeeded) {
+                self.upgradeSchema12(event.target.transaction, function() {
+                  self.upgradeSchema13(event.target.transaction, next);
+                });
+              } else {
+                self.upgradeSchema13(event.target.transaction, next);
+              }
+            });
             break;
           case 14:
             if (DEBUG) debug("Upgrade to version 15. Add deliveryTimestamp.");
             self.upgradeSchema14(event.target.transaction, next);
             break;
           case 15:
             if (DEBUG) debug("Upgrade to version 16. Add ICC ID for each message.");
             self.upgradeSchema15(event.target.transaction, next);
@@ -873,16 +884,39 @@ MobileMessageDatabaseService.prototype =
         delete messageRecord.deliveryStatus;
         cursor.update(messageRecord);
       }
       cursor.continue();
     };
   },
 
   /**
+   * Check if we need to re-upgrade the DB schema 12.
+   */
+  needReUpgradeSchema12: function needReUpgradeSchema12(transaction, callback) {
+    let messageStore = transaction.objectStore(MESSAGE_STORE_NAME);
+
+    messageStore.openCursor().onsuccess = function(event) {
+      let cursor = event.target.result;
+      if (!cursor) {
+        callback(false);
+        return;
+      }
+
+      let messageRecord = cursor.value;
+      if (messageRecord.type == "mms" &&
+          messageRecord.deliveryInfo === undefined) {
+        callback(true);
+        return;
+      }
+      cursor.continue();
+    };
+  },
+
+  /**
    * Fix the wrong participants.
    */
   upgradeSchema13: function upgradeSchema13(transaction, next) {
     let participantStore = transaction.objectStore(PARTICIPANT_STORE_NAME);
     let threadStore = transaction.objectStore(THREAD_STORE_NAME);
     let messageStore = transaction.objectStore(MESSAGE_STORE_NAME);
     let self = this;