Przeglądaj źródła

support of downgrading database schema

tobiaskaminsky 7 lat temu
rodzic
commit
e1e14a3588

+ 8 - 0
src/main/java/com/owncloud/android/providers/FileContentProvider.java

@@ -85,6 +85,7 @@ public class FileContentProvider extends ContentProvider {
     private static final String TEXT = " TEXT, ";
     private static final String ALTER_TABLE = "ALTER TABLE ";
     private static final String ADD_COLUMN = " ADD COLUMN ";
+    private static final String REMOVE_COLUMN = " REMOVE COLUMN ";
     private static final String UPGRADE_VERSION_MSG = "OUT of the ADD in onUpgrade; oldVersion == %d, newVersion == %d";
 
     @Override
@@ -1153,6 +1154,13 @@ public class FileContentProvider extends ContentProvider {
                 Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
             }
         }
+
+        @Override
+        public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
+            if (oldVersion == 25 && newVersion == 24) {
+                // nothing needs to be done as the upgrade was adding columns only if they did not exist
+            }
+        }
     }
 
     private boolean checkIfColumnExists(SQLiteDatabase database, String table, String column) {