Bug 1387053 - Make sure we don't do DB migration multiple times. r?rnewman draft
authorEdouard Oger <eoger@fastmail.com>
Thu, 03 Aug 2017 11:04:44 -0400
changeset 620548 c9c0b7d5986f8ea6e26758d034f3757b48d6cd45
parent 620494 fa1da3c0b200abbd9cfab3cab19962824314044e
child 640735 26e8c6953c742151e21cb3f4afa6bc47176b77e4
push id72078
push userbmo:eoger@fastmail.com
push dateThu, 03 Aug 2017 15:05:03 +0000
reviewersrnewman
bugs1387053
milestone57.0a1
Bug 1387053 - Make sure we don't do DB migration multiple times. r?rnewman MozReview-Commit-ID: I799FUjIG4M
mobile/android/services/src/main/java/org/mozilla/gecko/sync/repositories/android/ClientsDatabase.java
--- a/mobile/android/services/src/main/java/org/mozilla/gecko/sync/repositories/android/ClientsDatabase.java
+++ b/mobile/android/services/src/main/java/org/mozilla/gecko/sync/repositories/android/ClientsDatabase.java
@@ -102,26 +102,26 @@ public class ClientsDatabase extends Cac
     if (oldVersion < 2) {
       // For now we'll just drop and recreate the tables.
       db.execSQL("DROP TABLE IF EXISTS " + TBL_CLIENTS);
       db.execSQL("DROP TABLE IF EXISTS " + TBL_COMMANDS);
       onCreate(db);
       return;
     }
 
-    if (newVersion >= 3) {
+    if (oldVersion < 3 && newVersion >= 3) {
       // Add the optional columns to clients.
       db.execSQL("ALTER TABLE " + TBL_CLIENTS + " ADD COLUMN " + COL_FORMFACTOR + " TEXT");
       db.execSQL("ALTER TABLE " + TBL_CLIENTS + " ADD COLUMN " + COL_OS + " TEXT");
       db.execSQL("ALTER TABLE " + TBL_CLIENTS + " ADD COLUMN " + COL_APPLICATION + " TEXT");
       db.execSQL("ALTER TABLE " + TBL_CLIENTS + " ADD COLUMN " + COL_APP_PACKAGE + " TEXT");
       db.execSQL("ALTER TABLE " + TBL_CLIENTS + " ADD COLUMN " + COL_DEVICE + " TEXT");
     }
 
-    if (newVersion >= 4) {
+    if (oldVersion < 4 && newVersion >= 4) {
       db.execSQL("ALTER TABLE " + TBL_CLIENTS + " ADD COLUMN " + COL_FXA_DEVICE_ID + " TEXT");
       db.execSQL("CREATE INDEX idx_fxa_device_id ON " + TBL_CLIENTS + "(" + COL_FXA_DEVICE_ID + ")");
     }
   }
 
   public void wipeDB() {
     SQLiteDatabase db = this.getCachedWritableDatabase();
     onUpgrade(db, 0, SCHEMA_VERSION);