Bug 1128523 - Don't alter reading list table if it was created with the new schema in an earlier migration. r=rnewman, a=lmandel
authorMargaret Leibovic <margaret.leibovic@gmail.com>
Wed, 04 Feb 2015 13:56:53 -0800
changeset 249653 1b785ad1df000a2c17a01f184173539854d14cca
parent 249652 04d93fda6f3f07140a52cdb702fa3bce03426859
child 249654 f29179ce227b10fff495416758a79b4aa3e79f93
push id4489
push userraliiev@mozilla.com
push dateMon, 23 Feb 2015 15:17:55 +0000
treeherdermozilla-beta@fd7c3dc24146 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrnewman, lmandel
bugs1128523
milestone37.0a2
Bug 1128523 - Don't alter reading list table if it was created with the new schema in an earlier migration. r=rnewman, a=lmandel
mobile/android/base/db/BrowserDatabaseHelper.java
--- a/mobile/android/base/db/BrowserDatabaseHelper.java
+++ b/mobile/android/base/db/BrowserDatabaseHelper.java
@@ -19,16 +19,17 @@ import org.mozilla.gecko.db.BrowserContr
 import static org.mozilla.gecko.db.DBUtils.qualifyColumn;
 
 import android.content.ContentValues;
 import android.content.Context;
 import android.database.Cursor;
 import android.database.DatabaseUtils;
 import android.database.SQLException;
 import android.database.sqlite.SQLiteDatabase;
+import android.database.sqlite.SQLiteException;
 import android.database.sqlite.SQLiteOpenHelper;
 import android.net.Uri;
 import android.os.Build;
 import android.util.Log;
 
 
 final class BrowserDatabaseHelper extends SQLiteOpenHelper {
 
@@ -762,22 +763,28 @@ final class BrowserDatabaseHelper extend
 
     private void upgradeDatabaseFrom19to20(SQLiteDatabase db) {
         createSearchHistoryTable(db);
     }
 
     private void upgradeDatabaseFrom21to22(SQLiteDatabase db) {
         debug("Adding CONTENT_STATUS column to reading list table.");
 
-        db.execSQL("ALTER TABLE " + TABLE_READING_LIST +
-                   " ADD COLUMN " + ReadingListItems.CONTENT_STATUS +
-                   " TINYINT DEFAULT " + ReadingListItems.STATUS_UNFETCHED);
+        try {
+            db.execSQL("ALTER TABLE " + TABLE_READING_LIST +
+                       " ADD COLUMN " + ReadingListItems.CONTENT_STATUS +
+                       " TINYINT DEFAULT " + ReadingListItems.STATUS_UNFETCHED);
 
-        db.execSQL("CREATE INDEX reading_list_content_status ON " + TABLE_READING_LIST + "("
-                + ReadingListItems.CONTENT_STATUS + ")");
+            db.execSQL("CREATE INDEX reading_list_content_status ON " + TABLE_READING_LIST + "("
+                    + ReadingListItems.CONTENT_STATUS + ")");
+        } catch (SQLiteException e) {
+            // We're betting that an error here means that the table already has the column,
+            // so we're failing due to the duplicate column name.
+            Log.e(LOGTAG, "Error upgrading database from 21 to 22", e);
+        }
     }
 
     private void createV19CombinedView(SQLiteDatabase db) {
         db.execSQL("DROP VIEW IF EXISTS " + VIEW_COMBINED);
         db.execSQL("DROP VIEW IF EXISTS " + VIEW_COMBINED_WITH_FAVICONS);
 
         createCombinedViewOn19(db);
     }
@@ -835,17 +842,21 @@ final class BrowserDatabaseHelper extend
                     upgradeDatabaseFrom18to19(db);
                     break;
 
                 case 20:
                     upgradeDatabaseFrom19to20(db);
                     break;
 
                 case 22:
-                    upgradeDatabaseFrom21to22(db);
+                    if (oldVersion <= 17) {
+                         // We just created the right table in 17to18. Do nothing here.
+                    } else {
+                         upgradeDatabaseFrom21to22(db);
+                    }
                     break;
             }
         }
 
         for (Table table : BrowserProvider.sTables) {
             table.onUpgrade(db, oldVersion, newVersion);
         }