浏览代码

Fix column types and implement migrations

Signed-off-by: Álvaro Brey <alvaro.brey@nextcloud.com>
Álvaro Brey 2 年之前
父节点
当前提交
fdab7afbfd

+ 1687 - 0
app/src/main/java/com/nextcloud/client/database/LegacyMigrationHelper.java

@@ -0,0 +1,1687 @@
+/*
+ * Nextcloud Android client application
+ *
+ * @author Bartek Przybylski
+ * @author David A. Velasco
+ * @author masensio
+ * @author Álvaro Brey Vilas
+ * Copyright (C) 2011 Bartek Przybylski
+ * Copyright (C) 2016 ownCloud Inc.
+ * Copyright (C) 2022 Álvaro Brey Vilas
+ * Copyright (C) 2022 Nextcloud GmbH
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public
+ * License along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package com.nextcloud.client.database;
+
+import android.accounts.Account;
+import android.accounts.AccountManager;
+import android.content.ContentValues;
+import android.content.Context;
+import android.database.Cursor;
+import android.database.SQLException;
+import android.database.sqlite.SQLiteDatabase;
+import android.database.sqlite.SQLiteException;
+import android.net.Uri;
+
+import com.nextcloud.client.core.Clock;
+import com.owncloud.android.MainApp;
+import com.owncloud.android.datamodel.OCFile;
+import com.owncloud.android.datamodel.SyncedFolder;
+import com.owncloud.android.db.ProviderMeta;
+import com.owncloud.android.files.services.NameCollisionPolicy;
+import com.owncloud.android.lib.common.accounts.AccountUtils;
+import com.owncloud.android.lib.common.utils.Log_OC;
+import com.owncloud.android.providers.FileContentProvider;
+import com.owncloud.android.utils.FileStorageUtils;
+
+import java.io.File;
+import java.util.Locale;
+
+import androidx.sqlite.db.SupportSQLiteDatabase;
+import androidx.sqlite.db.SupportSQLiteQuery;
+import androidx.sqlite.db.SupportSQLiteQueryBuilder;
+
+public class LegacyMigrationHelper {
+
+    private static final String TAG = LegacyMigrationHelper.class.getSimpleName();
+
+    private static final String ALTER_TABLE = "ALTER TABLE ";
+    private static final String ADD_COLUMN = " ADD COLUMN ";
+    private static final String INTEGER = " INTEGER, ";
+    private static final String TEXT = " TEXT, ";
+
+    private static final String UPGRADE_VERSION_MSG = "OUT of the ADD in onUpgrade; oldVersion == %d, newVersion == %d";
+
+    private static final String[] PROJECTION_FILE_AND_STORAGE_PATH = new String[]{
+        ProviderMeta.ProviderTableMeta._ID, ProviderMeta.ProviderTableMeta.FILE_STORAGE_PATH, ProviderMeta.ProviderTableMeta.FILE_PATH
+    };
+    
+    private final Context context;
+    private final Clock clock;
+
+    public LegacyMigrationHelper(Context context, Clock clock) {
+        this.context = context;
+        this.clock = clock;
+    }
+
+    public void onUpgrade(SupportSQLiteDatabase db, int oldVersion, int newVersion) {
+        Log_OC.i(TAG, "Entering in onUpgrade");
+        boolean upgraded = false;
+        if (oldVersion == 1 && newVersion >= 2) {
+            Log_OC.i(TAG, "Entering in the #2 ADD in onUpgrade");
+            db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.FILE_TABLE_NAME +
+                           ADD_COLUMN + ProviderMeta.ProviderTableMeta.FILE_KEEP_IN_SYNC + " INTEGER " +
+                           " DEFAULT 0");
+            upgraded = true;
+        }
+        if (oldVersion < 3 && newVersion >= 3) {
+            Log_OC.i(TAG, "Entering in the #3 ADD in onUpgrade");
+            db.beginTransaction();
+            try {
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.FILE_TABLE_NAME +
+                               ADD_COLUMN + ProviderMeta.ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA +
+                               " INTEGER " + " DEFAULT 0");
+
+                // assume there are not local changes pending to upload
+                db.execSQL("UPDATE " + ProviderMeta.ProviderTableMeta.FILE_TABLE_NAME +
+                               " SET " + ProviderMeta.ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA + " = "
+                               + System.currentTimeMillis() +
+                               " WHERE " + ProviderMeta.ProviderTableMeta.FILE_STORAGE_PATH + " IS NOT NULL");
+
+                upgraded = true;
+                db.setTransactionSuccessful();
+            } finally {
+                db.endTransaction();
+            }
+        }
+        if (oldVersion < 4 && newVersion >= 4) {
+            Log_OC.i(TAG, "Entering in the #4 ADD in onUpgrade");
+            db.beginTransaction();
+            try {
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.FILE_TABLE_NAME +
+                               ADD_COLUMN + ProviderMeta.ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA +
+                               " INTEGER " + " DEFAULT 0");
+
+                db.execSQL("UPDATE " + ProviderMeta.ProviderTableMeta.FILE_TABLE_NAME +
+                               " SET " + ProviderMeta.ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA + " = " +
+                               ProviderMeta.ProviderTableMeta.FILE_MODIFIED +
+                               " WHERE " + ProviderMeta.ProviderTableMeta.FILE_STORAGE_PATH + " IS NOT NULL");
+
+                upgraded = true;
+                db.setTransactionSuccessful();
+            } finally {
+                db.endTransaction();
+            }
+        }
+
+        if (!upgraded) {
+            Log_OC.i(TAG, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
+        }
+
+        if (oldVersion < 5 && newVersion >= 5) {
+            Log_OC.i(TAG, "Entering in the #5 ADD in onUpgrade");
+            db.beginTransaction();
+            try {
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.FILE_TABLE_NAME +
+                               ADD_COLUMN + ProviderMeta.ProviderTableMeta.FILE_ETAG + " TEXT " +
+                               " DEFAULT NULL");
+
+                upgraded = true;
+                db.setTransactionSuccessful();
+            } finally {
+                db.endTransaction();
+            }
+        }
+        if (!upgraded) {
+            Log_OC.i(TAG, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
+        }
+
+        if (oldVersion < 6 && newVersion >= 6) {
+            Log_OC.i(TAG, "Entering in the #6 ADD in onUpgrade");
+            db.beginTransaction();
+            try {
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.FILE_TABLE_NAME +
+                               ADD_COLUMN + ProviderMeta.ProviderTableMeta.FILE_SHARED_VIA_LINK + " INTEGER " +
+                               " DEFAULT 0");
+
+                // Create table OCShares
+                createOCSharesTable(db);
+
+                upgraded = true;
+                db.setTransactionSuccessful();
+            } finally {
+                db.endTransaction();
+            }
+        }
+        if (!upgraded) {
+            Log_OC.i(TAG, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
+        }
+
+        if (oldVersion < 7 && newVersion >= 7) {
+            Log_OC.i(TAG, "Entering in the #7 ADD in onUpgrade");
+            db.beginTransaction();
+            try {
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.FILE_TABLE_NAME +
+                               ADD_COLUMN + ProviderMeta.ProviderTableMeta.FILE_PERMISSIONS + " TEXT " +
+                               " DEFAULT NULL");
+
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.FILE_TABLE_NAME +
+                               ADD_COLUMN + ProviderMeta.ProviderTableMeta.FILE_REMOTE_ID + " TEXT " +
+                               " DEFAULT NULL");
+
+                upgraded = true;
+                db.setTransactionSuccessful();
+            } finally {
+                db.endTransaction();
+            }
+        }
+        if (!upgraded) {
+            Log_OC.i(TAG, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
+        }
+
+        if (oldVersion < 8 && newVersion >= 8) {
+            Log_OC.i(TAG, "Entering in the #8 ADD in onUpgrade");
+            db.beginTransaction();
+            try {
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.FILE_TABLE_NAME +
+                               ADD_COLUMN + ProviderMeta.ProviderTableMeta.FILE_UPDATE_THUMBNAIL + " INTEGER " +
+                               " DEFAULT 0");
+
+                upgraded = true;
+                db.setTransactionSuccessful();
+            } finally {
+                db.endTransaction();
+            }
+        }
+        if (!upgraded) {
+            Log_OC.i(TAG, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
+        }
+
+        if (oldVersion < 9 && newVersion >= 9) {
+            Log_OC.i(TAG, "Entering in the #9 ADD in onUpgrade");
+            db.beginTransaction();
+            try {
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.FILE_TABLE_NAME +
+                               ADD_COLUMN + ProviderMeta.ProviderTableMeta.FILE_IS_DOWNLOADING + " INTEGER " +
+                               " DEFAULT 0");
+
+                upgraded = true;
+                db.setTransactionSuccessful();
+            } finally {
+                db.endTransaction();
+            }
+        }
+        if (!upgraded) {
+            Log_OC.i(TAG, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
+        }
+
+        if (oldVersion < 10 && newVersion >= 10) {
+            Log_OC.i(TAG, "Entering in the #10 ADD in onUpgrade");
+            updateAccountName(db);
+            upgraded = true;
+        }
+        if (!upgraded) {
+            Log_OC.i(TAG, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
+        }
+
+        if (oldVersion < 11 && newVersion >= 11) {
+            Log_OC.i(TAG, "Entering in the #11 ADD in onUpgrade");
+            db.beginTransaction();
+            try {
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.FILE_TABLE_NAME +
+                               ADD_COLUMN + ProviderMeta.ProviderTableMeta.FILE_ETAG_IN_CONFLICT + " TEXT " +
+                               " DEFAULT NULL");
+
+                upgraded = true;
+                db.setTransactionSuccessful();
+            } finally {
+                db.endTransaction();
+            }
+        }
+
+        if (!upgraded) {
+            Log_OC.i(TAG, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
+        }
+
+        if (oldVersion < 12 && newVersion >= 12) {
+            Log_OC.i(TAG, "Entering in the #12 ADD in onUpgrade");
+            db.beginTransaction();
+            try {
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.FILE_TABLE_NAME +
+                               ADD_COLUMN + ProviderMeta.ProviderTableMeta.FILE_SHARED_WITH_SHAREE + " INTEGER " +
+                               " DEFAULT 0");
+                upgraded = true;
+                db.setTransactionSuccessful();
+            } finally {
+                db.endTransaction();
+            }
+        }
+        if (!upgraded) {
+            Log_OC.i(TAG, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
+        }
+
+        if (oldVersion < 13 && newVersion >= 13) {
+            Log_OC.i(TAG, "Entering in the #13 ADD in onUpgrade");
+            db.beginTransaction();
+            try {
+                // Create capabilities table
+                createCapabilitiesTable(db);
+                upgraded = true;
+                db.setTransactionSuccessful();
+            } finally {
+                db.endTransaction();
+            }
+        }
+
+        if (oldVersion < 14 && newVersion >= 14) {
+            Log_OC.i(TAG, "Entering in the #14 ADD in onUpgrade");
+            db.beginTransaction();
+            try {
+                // drop old instant_upload table
+                db.execSQL("DROP TABLE IF EXISTS " + "instant_upload" + ";");
+                // Create uploads table
+                createUploadsTable(db);
+                upgraded = true;
+                db.setTransactionSuccessful();
+            } finally {
+                db.endTransaction();
+            }
+        }
+
+        if (oldVersion < 15 && newVersion >= 15) {
+            Log_OC.i(TAG, "Entering in the #15 ADD in onUpgrade");
+            db.beginTransaction();
+            try {
+                // drop old capabilities table
+                db.execSQL("DROP TABLE IF EXISTS " + "capabilities" + ";");
+                // Create uploads table
+                createCapabilitiesTable(db);
+                upgraded = true;
+                db.setTransactionSuccessful();
+            } finally {
+                db.endTransaction();
+            }
+        }
+
+        if (oldVersion < 16 && newVersion >= 16) {
+            Log_OC.i(TAG, "Entering in the #16 ADD synced folders table");
+            db.beginTransaction();
+            try {
+                // Create synced folders table
+                createSyncedFoldersTable(db);
+                upgraded = true;
+                db.setTransactionSuccessful();
+            } finally {
+                db.endTransaction();
+            }
+        }
+
+        if (!upgraded) {
+            Log_OC.i(TAG, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
+        }
+
+        if (oldVersion < 17 && newVersion >= 17) {
+            Log_OC.i(TAG, "Entering in the #17 ADD in onUpgrade");
+            db.beginTransaction();
+            try {
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.FILE_TABLE_NAME +
+                               ADD_COLUMN + ProviderMeta.ProviderTableMeta.FILE_FAVORITE +
+                               " INTEGER " + " DEFAULT 0");
+
+                upgraded = true;
+                db.setTransactionSuccessful();
+            } finally {
+                db.endTransaction();
+            }
+        }
+
+        if (!upgraded) {
+            Log_OC.i(TAG, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
+        }
+
+        if (oldVersion < 18 && newVersion >= 18) {
+            Log_OC.i(TAG, "Entering in the #18 Adding external link column to capabilities");
+            db.beginTransaction();
+            try {
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.CAPABILITIES_TABLE_NAME +
+                               ADD_COLUMN + ProviderMeta.ProviderTableMeta.CAPABILITIES_EXTERNAL_LINKS +
+                               " INTEGER " + " DEFAULT -1");
+
+                upgraded = true;
+                db.setTransactionSuccessful();
+            } finally {
+                db.endTransaction();
+            }
+        }
+
+        if (!upgraded) {
+            Log_OC.i(TAG, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
+        }
+
+        if (oldVersion < 19 && newVersion >= 19) {
+            Log_OC.i(TAG, "Entering in the #19 Adding external link column to capabilities");
+            db.beginTransaction();
+            try {
+                createExternalLinksTable(db);
+                upgraded = true;
+                db.setTransactionSuccessful();
+            } finally {
+                db.endTransaction();
+            }
+        }
+
+        if (!upgraded) {
+            Log_OC.i(TAG, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
+        }
+
+        if (oldVersion < 20 && newVersion >= 20) {
+            Log_OC.i(TAG, "Entering in the #20 Adding arbitrary data table");
+            db.beginTransaction();
+            try {
+                createArbitraryData(db);
+                upgraded = true;
+                db.setTransactionSuccessful();
+            } finally {
+                db.endTransaction();
+            }
+        }
+
+        if (!upgraded) {
+            Log_OC.i(TAG, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
+        }
+
+        if (oldVersion < 21 && newVersion >= 21) {
+            Log_OC.i(TAG, "Entering in the #21 Adding virtual table");
+            db.beginTransaction();
+            try {
+                createVirtualTable(db);
+                upgraded = true;
+                db.setTransactionSuccessful();
+            } finally {
+                db.endTransaction();
+            }
+        }
+
+        if (!upgraded) {
+            Log_OC.i(TAG, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
+        }
+
+        if (oldVersion < 22 && newVersion >= 22) {
+            Log_OC.i(TAG, "Entering in the #22 Adding user theming to capabilities table");
+            db.beginTransaction();
+            try {
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.CAPABILITIES_TABLE_NAME +
+                               ADD_COLUMN + ProviderMeta.ProviderTableMeta.CAPABILITIES_SERVER_NAME + " TEXT ");
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.CAPABILITIES_TABLE_NAME +
+                               ADD_COLUMN + ProviderMeta.ProviderTableMeta.CAPABILITIES_SERVER_COLOR + " TEXT ");
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.CAPABILITIES_TABLE_NAME +
+                               ADD_COLUMN + ProviderMeta.ProviderTableMeta.CAPABILITIES_SERVER_BACKGROUND_URL + " TEXT ");
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.CAPABILITIES_TABLE_NAME +
+                               ADD_COLUMN + ProviderMeta.ProviderTableMeta.CAPABILITIES_SERVER_SLOGAN + " TEXT ");
+                upgraded = true;
+                db.setTransactionSuccessful();
+            } finally {
+                db.endTransaction();
+            }
+        }
+
+        if (!upgraded) {
+            Log_OC.i(TAG, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
+        }
+
+        if (oldVersion < 23 && newVersion >= 23) {
+            Log_OC.i(TAG, "Entering in the #23 adding type column for synced folders, Create filesystem table");
+            db.beginTransaction();
+            try {
+                // add type column default being CUSTOM (0)
+                if (!checkIfColumnExists(db, ProviderMeta.ProviderTableMeta.SYNCED_FOLDERS_TABLE_NAME,
+                                         ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_TYPE)) {
+                    Log_OC.i(TAG, "Add type column and default value 0 (CUSTOM) to synced_folders table");
+                    db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.SYNCED_FOLDERS_TABLE_NAME +
+                                   ADD_COLUMN + ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_TYPE +
+                                   " INTEGER " + " DEFAULT 0");
+                } else {
+                    Log_OC.i(TAG, "Type column of synced_folders table already exists");
+                }
+
+                if (!checkIfColumnExists(db, ProviderMeta.ProviderTableMeta.UPLOADS_TABLE_NAME,
+                                         ProviderMeta.ProviderTableMeta.UPLOADS_IS_WIFI_ONLY)) {
+                    Log_OC.i(TAG, "Add charging and wifi columns to uploads");
+                    db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.UPLOADS_TABLE_NAME +
+                                   ADD_COLUMN + ProviderMeta.ProviderTableMeta.UPLOADS_IS_WIFI_ONLY +
+                                   " INTEGER " + " DEFAULT 0");
+                } else {
+                    Log_OC.i(TAG, "Wifi column of uploads table already exists");
+                }
+
+                if (!checkIfColumnExists(db, ProviderMeta.ProviderTableMeta.UPLOADS_TABLE_NAME,
+                                         ProviderMeta.ProviderTableMeta.UPLOADS_IS_WHILE_CHARGING_ONLY)) {
+                    db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.UPLOADS_TABLE_NAME +
+                                   ADD_COLUMN + ProviderMeta.ProviderTableMeta.UPLOADS_IS_WHILE_CHARGING_ONLY +
+                                   " INTEGER " + " DEFAULT 0");
+                } else {
+                    Log_OC.i(TAG, "Charging column of uploads table already exists");
+                }
+
+                // create Filesystem table
+                Log_OC.i(TAG, "Create filesystem table");
+                createFileSystemTable(db);
+
+                upgraded = true;
+                db.setTransactionSuccessful();
+
+            } catch (Throwable t) {
+                Log_OC.e(TAG, "ERROR!", t);
+            } finally {
+                db.endTransaction();
+            }
+        }
+
+        if (!upgraded) {
+            Log_OC.i(TAG, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
+        }
+
+        if (oldVersion < 24 && newVersion >= 24) {
+            Log_OC.i(TAG, "Entering in the #24 Re-adding user theming to capabilities table");
+            db.beginTransaction();
+            try {
+                if (!checkIfColumnExists(db, ProviderMeta.ProviderTableMeta.CAPABILITIES_TABLE_NAME,
+                                         ProviderMeta.ProviderTableMeta.CAPABILITIES_SERVER_NAME)) {
+                    db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.CAPABILITIES_TABLE_NAME +
+                                   ADD_COLUMN + ProviderMeta.ProviderTableMeta.CAPABILITIES_SERVER_NAME + " TEXT ");
+                }
+
+                if (!checkIfColumnExists(db, ProviderMeta.ProviderTableMeta.CAPABILITIES_TABLE_NAME,
+                                         ProviderMeta.ProviderTableMeta.CAPABILITIES_SERVER_COLOR)) {
+                    db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.CAPABILITIES_TABLE_NAME +
+                                   ADD_COLUMN + ProviderMeta.ProviderTableMeta.CAPABILITIES_SERVER_COLOR + " TEXT ");
+                }
+
+                if (!checkIfColumnExists(db, ProviderMeta.ProviderTableMeta.CAPABILITIES_TABLE_NAME,
+                                         ProviderMeta.ProviderTableMeta.CAPABILITIES_SERVER_BACKGROUND_URL)) {
+                    db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.CAPABILITIES_TABLE_NAME +
+                                   ADD_COLUMN + ProviderMeta.ProviderTableMeta.CAPABILITIES_SERVER_BACKGROUND_URL + " TEXT ");
+                }
+
+                if (!checkIfColumnExists(db, ProviderMeta.ProviderTableMeta.CAPABILITIES_TABLE_NAME,
+                                         ProviderMeta.ProviderTableMeta.CAPABILITIES_SERVER_SLOGAN)) {
+                    db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.CAPABILITIES_TABLE_NAME +
+                                   ADD_COLUMN + ProviderMeta.ProviderTableMeta.CAPABILITIES_SERVER_SLOGAN + " TEXT ");
+                }
+
+                upgraded = true;
+                db.setTransactionSuccessful();
+            } finally {
+                db.endTransaction();
+            }
+        }
+
+        if (!upgraded) {
+            Log_OC.i(TAG, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
+        }
+
+        if (oldVersion < 25 && newVersion >= 25) {
+            Log_OC.i(TAG, "Entering in the #25 Adding encryption flag to file");
+            db.beginTransaction();
+            try {
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.FILE_TABLE_NAME +
+                               ADD_COLUMN + ProviderMeta.ProviderTableMeta.FILE_IS_ENCRYPTED + " INTEGER ");
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.FILE_TABLE_NAME +
+                               ADD_COLUMN + ProviderMeta.ProviderTableMeta.FILE_ENCRYPTED_NAME + " TEXT ");
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.CAPABILITIES_TABLE_NAME +
+                               ADD_COLUMN + ProviderMeta.ProviderTableMeta.CAPABILITIES_END_TO_END_ENCRYPTION + " INTEGER ");
+                upgraded = true;
+                db.setTransactionSuccessful();
+            } finally {
+                db.endTransaction();
+            }
+        }
+
+        if (!upgraded) {
+            Log_OC.i(TAG, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
+        }
+
+        if (oldVersion < 26 && newVersion >= 26) {
+            Log_OC.i(TAG, "Entering in the #26 Adding text and element color to capabilities");
+            db.beginTransaction();
+            try {
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.CAPABILITIES_TABLE_NAME +
+                               ADD_COLUMN + ProviderMeta.ProviderTableMeta.CAPABILITIES_SERVER_TEXT_COLOR + " TEXT ");
+
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.CAPABILITIES_TABLE_NAME +
+                               ADD_COLUMN + ProviderMeta.ProviderTableMeta.CAPABILITIES_SERVER_ELEMENT_COLOR + " TEXT ");
+
+                upgraded = true;
+                db.setTransactionSuccessful();
+            } finally {
+                db.endTransaction();
+            }
+        }
+
+        if (!upgraded) {
+            Log_OC.i(TAG, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
+        }
+
+        if (!upgraded) {
+            Log_OC.i(TAG, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
+        }
+
+        if (oldVersion < 27 && newVersion >= 27) {
+            Log_OC.i(TAG, "Entering in the #27 Adding token to ocUpload");
+            db.beginTransaction();
+            try {
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.UPLOADS_TABLE_NAME +
+                               ADD_COLUMN + ProviderMeta.ProviderTableMeta.UPLOADS_FOLDER_UNLOCK_TOKEN + " TEXT ");
+                upgraded = true;
+                db.setTransactionSuccessful();
+            } finally {
+                db.endTransaction();
+            }
+        }
+
+        if (!upgraded) {
+            Log_OC.i(TAG, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
+        }
+
+        if (oldVersion < 28 && newVersion >= 28) {
+            Log_OC.i(TAG, "Entering in the #28 Adding CRC32 column to filesystem table");
+            db.beginTransaction();
+            try {
+                if (!checkIfColumnExists(db, ProviderMeta.ProviderTableMeta.FILESYSTEM_TABLE_NAME,
+                                         ProviderMeta.ProviderTableMeta.FILESYSTEM_CRC32)) {
+                    db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.FILESYSTEM_TABLE_NAME +
+                                   ADD_COLUMN + ProviderMeta.ProviderTableMeta.FILESYSTEM_CRC32 + " TEXT ");
+                }
+                upgraded = true;
+                db.setTransactionSuccessful();
+            } finally {
+                db.endTransaction();
+            }
+        }
+
+        if (!upgraded) {
+            Log_OC.i(TAG, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
+        }
+
+        if (oldVersion < 29 && newVersion >= 29) {
+            Log_OC.i(TAG, "Entering in the #29 Adding background default/plain to capabilities");
+            db.beginTransaction();
+            try {
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.CAPABILITIES_TABLE_NAME +
+                               ADD_COLUMN + ProviderMeta.ProviderTableMeta.CAPABILITIES_SERVER_BACKGROUND_DEFAULT + " INTEGER ");
+
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.CAPABILITIES_TABLE_NAME +
+                               ADD_COLUMN + ProviderMeta.ProviderTableMeta.CAPABILITIES_SERVER_BACKGROUND_PLAIN + " INTEGER ");
+
+                upgraded = true;
+                db.setTransactionSuccessful();
+            } finally {
+                db.endTransaction();
+            }
+        }
+
+        if (!upgraded) {
+            Log_OC.i(TAG, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
+        }
+
+        if (oldVersion < 30 && newVersion >= 30) {
+            Log_OC.i(TAG, "Entering in the #30 Re-add 25, 26 if needed");
+            db.beginTransaction();
+            try {
+                if (!checkIfColumnExists(db, ProviderMeta.ProviderTableMeta.FILE_TABLE_NAME,
+                                         ProviderMeta.ProviderTableMeta.FILE_IS_ENCRYPTED)) {
+                    db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.FILE_TABLE_NAME +
+                                   ADD_COLUMN + ProviderMeta.ProviderTableMeta.FILE_IS_ENCRYPTED + " INTEGER ");
+                }
+                if (!checkIfColumnExists(db, ProviderMeta.ProviderTableMeta.FILE_TABLE_NAME,
+                                         ProviderMeta.ProviderTableMeta.FILE_ENCRYPTED_NAME)) {
+                    db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.FILE_TABLE_NAME +
+                                   ADD_COLUMN + ProviderMeta.ProviderTableMeta.FILE_ENCRYPTED_NAME + " TEXT ");
+                }
+                if (oldVersion > FileContentProvider.ARBITRARY_DATA_TABLE_INTRODUCTION_VERSION) {
+                    if (!checkIfColumnExists(db, ProviderMeta.ProviderTableMeta.CAPABILITIES_TABLE_NAME,
+                                             ProviderMeta.ProviderTableMeta.CAPABILITIES_END_TO_END_ENCRYPTION)) {
+                        db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.CAPABILITIES_TABLE_NAME +
+                                       ADD_COLUMN + ProviderMeta.ProviderTableMeta.CAPABILITIES_END_TO_END_ENCRYPTION + " INTEGER ");
+                    }
+                    if (!checkIfColumnExists(db, ProviderMeta.ProviderTableMeta.CAPABILITIES_TABLE_NAME,
+                                             ProviderMeta.ProviderTableMeta.CAPABILITIES_SERVER_TEXT_COLOR)) {
+                        db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.CAPABILITIES_TABLE_NAME +
+                                       ADD_COLUMN + ProviderMeta.ProviderTableMeta.CAPABILITIES_SERVER_TEXT_COLOR + " TEXT ");
+                    }
+                    if (!checkIfColumnExists(db, ProviderMeta.ProviderTableMeta.CAPABILITIES_TABLE_NAME,
+                                             ProviderMeta.ProviderTableMeta.CAPABILITIES_SERVER_ELEMENT_COLOR)) {
+                        db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.CAPABILITIES_TABLE_NAME +
+                                       ADD_COLUMN + ProviderMeta.ProviderTableMeta.CAPABILITIES_SERVER_ELEMENT_COLOR + " TEXT ");
+                    }
+                    if (!checkIfColumnExists(db, ProviderMeta.ProviderTableMeta.FILESYSTEM_TABLE_NAME,
+                                             ProviderMeta.ProviderTableMeta.FILESYSTEM_CRC32)) {
+                        try {
+                            db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.FILESYSTEM_TABLE_NAME +
+                                           ADD_COLUMN + ProviderMeta.ProviderTableMeta.FILESYSTEM_CRC32 + " TEXT ");
+                        } catch (SQLiteException e) {
+                            Log_OC.d(TAG, "Known problem on adding same column twice when upgrading from 24->30");
+                        }
+                    }
+                }
+
+                upgraded = true;
+                db.setTransactionSuccessful();
+            } finally {
+                db.endTransaction();
+            }
+        }
+
+        if (!upgraded) {
+            Log_OC.i(TAG, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
+        }
+
+        if (oldVersion < 31 && newVersion >= 31) {
+            Log_OC.i(TAG, "Entering in the #31 add mount type");
+            db.beginTransaction();
+            try {
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.FILE_TABLE_NAME +
+                               ADD_COLUMN + ProviderMeta.ProviderTableMeta.FILE_MOUNT_TYPE + " INTEGER ");
+
+                upgraded = true;
+                db.setTransactionSuccessful();
+            } finally {
+                db.endTransaction();
+            }
+        }
+
+        if (!upgraded) {
+            Log_OC.i(TAG, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
+        }
+
+        if (oldVersion < 32 && newVersion >= 32) {
+            Log_OC.i(TAG, "Entering in the #32 add ocshares.is_password_protected");
+            db.beginTransaction();
+            try {
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.OCSHARES_TABLE_NAME +
+                               ADD_COLUMN + ProviderMeta.ProviderTableMeta.OCSHARES_IS_PASSWORD_PROTECTED + " INTEGER "); // boolean
+
+                upgraded = true;
+                db.setTransactionSuccessful();
+            } finally {
+                db.endTransaction();
+            }
+        }
+
+        if (!upgraded) {
+            Log_OC.i(TAG, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
+        }
+
+        if (oldVersion < 33 && newVersion >= 33) {
+            Log_OC.i(TAG, "Entering in the #3 Adding activity to capability");
+            db.beginTransaction();
+            try {
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.CAPABILITIES_TABLE_NAME +
+                               ADD_COLUMN + ProviderMeta.ProviderTableMeta.CAPABILITIES_ACTIVITY + " INTEGER ");
+                upgraded = true;
+                db.setTransactionSuccessful();
+            } finally {
+                db.endTransaction();
+            }
+        }
+
+        if (!upgraded) {
+            Log_OC.i(TAG, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
+        }
+
+        if (oldVersion < 34 && newVersion >= 34) {
+            Log_OC.i(TAG, "Entering in the #34 add redirect to external links");
+            db.beginTransaction();
+            try {
+                if (!checkIfColumnExists(db, ProviderMeta.ProviderTableMeta.EXTERNAL_LINKS_TABLE_NAME,
+                                         ProviderMeta.ProviderTableMeta.EXTERNAL_LINKS_REDIRECT)) {
+                    db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.EXTERNAL_LINKS_TABLE_NAME +
+                                   ADD_COLUMN + ProviderMeta.ProviderTableMeta.EXTERNAL_LINKS_REDIRECT + " INTEGER "); // boolean
+                }
+                upgraded = true;
+                db.setTransactionSuccessful();
+            } finally {
+                db.endTransaction();
+            }
+        }
+
+        if (!upgraded) {
+            Log_OC.i(TAG, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
+        }
+
+        if (oldVersion < 35 && newVersion >= 35) {
+            Log_OC.i(TAG, "Entering in the #35 add note to share table");
+            db.beginTransaction();
+            try {
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.OCSHARES_TABLE_NAME +
+                               ADD_COLUMN + ProviderMeta.ProviderTableMeta.OCSHARES_NOTE + " TEXT ");
+
+                upgraded = true;
+                db.setTransactionSuccessful();
+            } finally {
+                db.endTransaction();
+            }
+        }
+
+        if (!upgraded) {
+            Log_OC.i(TAG, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
+        }
+
+        if (oldVersion < 36 && newVersion >= 36) {
+            Log_OC.i(TAG, "Entering in the #36 add has-preview to file table");
+            db.beginTransaction();
+            try {
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.FILE_TABLE_NAME +
+                               ADD_COLUMN + ProviderMeta.ProviderTableMeta.FILE_HAS_PREVIEW + " INTEGER ");
+
+                upgraded = true;
+                db.setTransactionSuccessful();
+            } finally {
+                db.endTransaction();
+            }
+        }
+
+        if (!upgraded) {
+            Log_OC.i(TAG, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
+        }
+
+        if (oldVersion < 37 && newVersion >= 37) {
+            Log_OC.i(TAG, "Entering in the #37 add hide-download to share table");
+            db.beginTransaction();
+            try {
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.OCSHARES_TABLE_NAME +
+                               ADD_COLUMN + ProviderMeta.ProviderTableMeta.OCSHARES_HIDE_DOWNLOAD + " INTEGER ");
+
+                upgraded = true;
+                db.setTransactionSuccessful();
+            } finally {
+                db.endTransaction();
+            }
+        }
+
+        if (!upgraded) {
+            Log_OC.i(TAG, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
+        }
+
+        if (oldVersion < 38 && newVersion >= 38) {
+            Log_OC.i(TAG, "Entering in the #38 add richdocuments");
+            db.beginTransaction();
+            try {
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.CAPABILITIES_TABLE_NAME +
+                               ADD_COLUMN + ProviderMeta.ProviderTableMeta.CAPABILITIES_RICHDOCUMENT + " INTEGER "); // boolean
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.CAPABILITIES_TABLE_NAME +
+                               ADD_COLUMN + ProviderMeta.ProviderTableMeta.CAPABILITIES_RICHDOCUMENT_MIMETYPE_LIST + " TEXT "); // string
+
+                upgraded = true;
+                db.setTransactionSuccessful();
+            } finally {
+                db.endTransaction();
+            }
+        }
+
+        if (!upgraded) {
+            Log_OC.i(TAG, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
+        }
+
+        if (oldVersion < 39 && newVersion >= 39) {
+            Log_OC.i(TAG, "Entering in the #39 add richdocuments direct editing");
+            db.beginTransaction();
+            try {
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.CAPABILITIES_TABLE_NAME +
+                               ADD_COLUMN + ProviderMeta.ProviderTableMeta.CAPABILITIES_RICHDOCUMENT_DIRECT_EDITING + " INTEGER "); // bool
+
+                upgraded = true;
+                db.setTransactionSuccessful();
+            } finally {
+                db.endTransaction();
+            }
+        }
+
+        if (!upgraded) {
+            Log_OC.i(TAG, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
+        }
+
+        if (oldVersion < 40 && newVersion >= 40) {
+            Log_OC.i(TAG, "Entering in the #40 add unreadCommentsCount to file table");
+            db.beginTransaction();
+            try {
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.FILE_TABLE_NAME +
+                               ADD_COLUMN + ProviderMeta.ProviderTableMeta.FILE_UNREAD_COMMENTS_COUNT + " INTEGER ");
+
+                upgraded = true;
+                db.setTransactionSuccessful();
+            } finally {
+                db.endTransaction();
+            }
+        }
+
+        if (!upgraded) {
+            Log_OC.i(TAG, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
+        }
+
+        if (oldVersion < 41 && newVersion >= 41) {
+            Log_OC.i(TAG, "Entering in the #41 add eTagOnServer");
+            db.beginTransaction();
+            try {
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.FILE_TABLE_NAME +
+                               ADD_COLUMN + ProviderMeta.ProviderTableMeta.FILE_ETAG_ON_SERVER + " TEXT ");
+
+                upgraded = true;
+                db.setTransactionSuccessful();
+            } finally {
+                db.endTransaction();
+            }
+        }
+
+        if (!upgraded) {
+            Log_OC.i(TAG, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
+        }
+
+        if (oldVersion < 42 && newVersion >= 42) {
+            Log_OC.i(TAG, "Entering in the #42 add richDocuments templates");
+            db.beginTransaction();
+            try {
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.CAPABILITIES_TABLE_NAME +
+                               ADD_COLUMN + ProviderMeta.ProviderTableMeta.CAPABILITIES_RICHDOCUMENT_TEMPLATES + " INTEGER ");
+
+                upgraded = true;
+                db.setTransactionSuccessful();
+            } finally {
+                db.endTransaction();
+            }
+        }
+
+        if (!upgraded) {
+            Log_OC.i(TAG, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
+        }
+
+        if (oldVersion < 43 && newVersion >= 43) {
+            Log_OC.i(TAG, "Entering in the #43 add ownerId and owner display name to file table");
+            db.beginTransaction();
+            try {
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.FILE_TABLE_NAME +
+                               ADD_COLUMN + ProviderMeta.ProviderTableMeta.FILE_OWNER_ID + " TEXT ");
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.FILE_TABLE_NAME +
+                               ADD_COLUMN + ProviderMeta.ProviderTableMeta.FILE_OWNER_DISPLAY_NAME + " TEXT ");
+
+                upgraded = true;
+                db.setTransactionSuccessful();
+            } finally {
+                db.endTransaction();
+            }
+        }
+
+        if (!upgraded) {
+            Log_OC.i(TAG, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
+        }
+
+        if (oldVersion < 44 && newVersion >= 44) {
+            Log_OC.i(TAG, "Entering in the #44 add note to file table");
+            db.beginTransaction();
+            try {
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.FILE_TABLE_NAME +
+                               ADD_COLUMN + ProviderMeta.ProviderTableMeta.FILE_NOTE + " TEXT ");
+
+                upgraded = true;
+                db.setTransactionSuccessful();
+            } finally {
+                db.endTransaction();
+            }
+        }
+
+        if (!upgraded) {
+            Log_OC.i(TAG, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
+        }
+
+        if (oldVersion < 45 && newVersion >= 45) {
+            Log_OC.i(TAG, "Entering in the #45 add sharees to file table");
+            db.beginTransaction();
+            try {
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.FILE_TABLE_NAME +
+                               ADD_COLUMN + ProviderMeta.ProviderTableMeta.FILE_SHAREES + " TEXT ");
+
+                upgraded = true;
+                db.setTransactionSuccessful();
+            } finally {
+                db.endTransaction();
+            }
+        }
+
+        if (!upgraded) {
+            Log_OC.i(TAG, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
+        }
+
+        if (oldVersion < 46 && newVersion >= 46) {
+            Log_OC.i(TAG, "Entering in the #46 add optional mimetypes to capabilities table");
+            db.beginTransaction();
+            try {
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.CAPABILITIES_TABLE_NAME +
+                               ADD_COLUMN + ProviderMeta.ProviderTableMeta.CAPABILITIES_RICHDOCUMENT_OPTIONAL_MIMETYPE_LIST
+                               + " TEXT ");
+
+                upgraded = true;
+                db.setTransactionSuccessful();
+            } finally {
+                db.endTransaction();
+            }
+        }
+
+        if (!upgraded) {
+            Log_OC.i(TAG, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
+        }
+
+        if (oldVersion < 47 && newVersion >= 47) {
+            Log_OC.i(TAG, "Entering in the #47 add askForPassword to capability table");
+            db.beginTransaction();
+            try {
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.CAPABILITIES_TABLE_NAME +
+                               ADD_COLUMN + ProviderMeta.ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_ASK_FOR_OPTIONAL_PASSWORD +
+                               " INTEGER ");
+
+                upgraded = true;
+                db.setTransactionSuccessful();
+            } finally {
+                db.endTransaction();
+            }
+        }
+
+        if (!upgraded) {
+            Log_OC.i(TAG, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
+        }
+
+        if (oldVersion < 48 && newVersion >= 48) {
+            Log_OC.i(TAG, "Entering in the #48 add product name to capabilities table");
+            db.beginTransaction();
+            try {
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.CAPABILITIES_TABLE_NAME +
+                               ADD_COLUMN + ProviderMeta.ProviderTableMeta.CAPABILITIES_RICHDOCUMENT_PRODUCT_NAME + " TEXT ");
+
+                upgraded = true;
+                db.setTransactionSuccessful();
+            } finally {
+                db.endTransaction();
+            }
+        }
+
+        if (!upgraded) {
+            Log_OC.i(TAG, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
+        }
+
+        if (oldVersion < 49 && newVersion >= 49) {
+            Log_OC.i(TAG, "Entering in the #49 add extended support to capabilities table");
+            db.beginTransaction();
+            try {
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.CAPABILITIES_TABLE_NAME +
+                               ADD_COLUMN + ProviderMeta.ProviderTableMeta.CAPABILITIES_EXTENDED_SUPPORT + " INTEGER ");
+
+                upgraded = true;
+                db.setTransactionSuccessful();
+            } finally {
+                db.endTransaction();
+            }
+        }
+
+        if (!upgraded) {
+            Log_OC.i(TAG, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
+        }
+
+        if (oldVersion < 50 && newVersion >= 50) {
+            Log_OC.i(TAG, "Entering in the #50 add persistent enable date to synced_folders table");
+            db.beginTransaction();
+            try {
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.SYNCED_FOLDERS_TABLE_NAME +
+                               ADD_COLUMN + ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_ENABLED_TIMESTAMP_MS + " INTEGER ");
+
+                db.execSQL("UPDATE " + ProviderMeta.ProviderTableMeta.SYNCED_FOLDERS_TABLE_NAME + " SET " +
+                               ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_ENABLED_TIMESTAMP_MS + " = CASE " +
+                               " WHEN enabled = 0 THEN " + SyncedFolder.EMPTY_ENABLED_TIMESTAMP_MS + " " +
+                               " ELSE " + clock.getCurrentTime() +
+                               " END ");
+
+                upgraded = true;
+                db.setTransactionSuccessful();
+            } finally {
+                db.endTransaction();
+            }
+        }
+
+        if (!upgraded) {
+            Log_OC.i(TAG, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
+        }
+
+        if (oldVersion < 51 && newVersion >= 51) {
+            Log_OC.i(TAG, "Entering in the #51 add show/hide to folderSync table");
+            db.beginTransaction();
+            try {
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.SYNCED_FOLDERS_TABLE_NAME +
+                               ADD_COLUMN + ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_HIDDEN + " INTEGER ");
+
+                upgraded = true;
+                db.setTransactionSuccessful();
+            } finally {
+                db.endTransaction();
+            }
+        }
+
+        if (!upgraded) {
+            Log_OC.i(TAG, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
+        }
+
+        if (oldVersion < 52 && newVersion >= 52) {
+            Log_OC.i(TAG, "Entering in the #52 add etag for directEditing to capability");
+            db.beginTransaction();
+            try {
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.CAPABILITIES_TABLE_NAME +
+                               ADD_COLUMN + ProviderMeta.ProviderTableMeta.CAPABILITIES_DIRECT_EDITING_ETAG + " TEXT ");
+
+                upgraded = true;
+                db.setTransactionSuccessful();
+            } finally {
+                db.endTransaction();
+            }
+        }
+
+        if (!upgraded) {
+            Log_OC.i(TAG, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
+        }
+
+        if (oldVersion < 53 && newVersion >= 53) {
+            Log_OC.i(TAG, "Entering in the #53 add rich workspace to file table");
+            db.beginTransaction();
+            try {
+                if (!checkIfColumnExists(db, ProviderMeta.ProviderTableMeta.FILE_TABLE_NAME,
+                                         ProviderMeta.ProviderTableMeta.FILE_RICH_WORKSPACE)) {
+                    db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.FILE_TABLE_NAME +
+                                   ADD_COLUMN + ProviderMeta.ProviderTableMeta.FILE_RICH_WORKSPACE + " TEXT ");
+                }
+                upgraded = true;
+                db.setTransactionSuccessful();
+            } finally {
+                db.endTransaction();
+            }
+        }
+
+        if (!upgraded) {
+            Log_OC.i(TAG, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
+        }
+
+        if (oldVersion < 54 && newVersion >= 54) {
+            Log_OC.i(TAG, "Entering in the #54 add synced.existing," +
+                " rename uploads.force_overwrite to uploads.name_collision_policy");
+            db.beginTransaction();
+            try {
+                // Add synced.existing
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.SYNCED_FOLDERS_TABLE_NAME +
+                               ADD_COLUMN + ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_EXISTING + " INTEGER "); // boolean
+
+
+                // Rename uploads.force_overwrite to uploads.name_collision_policy
+                String tmpTableName = ProviderMeta.ProviderTableMeta.UPLOADS_TABLE_NAME + "_old";
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.UPLOADS_TABLE_NAME + " RENAME TO " + tmpTableName);
+                createUploadsTable(db);
+                db.execSQL("INSERT INTO " + ProviderMeta.ProviderTableMeta.UPLOADS_TABLE_NAME + " (" +
+                               ProviderMeta.ProviderTableMeta._ID + ", " +
+                               ProviderMeta.ProviderTableMeta.UPLOADS_LOCAL_PATH + ", " +
+                               ProviderMeta.ProviderTableMeta.UPLOADS_REMOTE_PATH + ", " +
+                               ProviderMeta.ProviderTableMeta.UPLOADS_ACCOUNT_NAME + ", " +
+                               ProviderMeta.ProviderTableMeta.UPLOADS_FILE_SIZE + ", " +
+                               ProviderMeta.ProviderTableMeta.UPLOADS_STATUS + ", " +
+                               ProviderMeta.ProviderTableMeta.UPLOADS_LOCAL_BEHAVIOUR + ", " +
+                               ProviderMeta.ProviderTableMeta.UPLOADS_UPLOAD_TIME + ", " +
+                               ProviderMeta.ProviderTableMeta.UPLOADS_NAME_COLLISION_POLICY + ", " +
+                               ProviderMeta.ProviderTableMeta.UPLOADS_IS_CREATE_REMOTE_FOLDER + ", " +
+                               ProviderMeta.ProviderTableMeta.UPLOADS_UPLOAD_END_TIMESTAMP + ", " +
+                               ProviderMeta.ProviderTableMeta.UPLOADS_LAST_RESULT + ", " +
+                               ProviderMeta.ProviderTableMeta.UPLOADS_IS_WHILE_CHARGING_ONLY + ", " +
+                               ProviderMeta.ProviderTableMeta.UPLOADS_IS_WIFI_ONLY + ", " +
+                               ProviderMeta.ProviderTableMeta.UPLOADS_CREATED_BY + ", " +
+                               ProviderMeta.ProviderTableMeta.UPLOADS_FOLDER_UNLOCK_TOKEN +
+                               ") " +
+                               " SELECT " +
+                               ProviderMeta.ProviderTableMeta._ID + ", " +
+                               ProviderMeta.ProviderTableMeta.UPLOADS_LOCAL_PATH + ", " +
+                               ProviderMeta.ProviderTableMeta.UPLOADS_REMOTE_PATH + ", " +
+                               ProviderMeta.ProviderTableMeta.UPLOADS_ACCOUNT_NAME + ", " +
+                               ProviderMeta.ProviderTableMeta.UPLOADS_FILE_SIZE + ", " +
+                               ProviderMeta.ProviderTableMeta.UPLOADS_STATUS + ", " +
+                               ProviderMeta.ProviderTableMeta.UPLOADS_LOCAL_BEHAVIOUR + ", " +
+                               ProviderMeta.ProviderTableMeta.UPLOADS_UPLOAD_TIME + ", " +
+                               "force_overwrite" + ", " + // See FileUploader.NameCollisionPolicy
+                               ProviderMeta.ProviderTableMeta.UPLOADS_IS_CREATE_REMOTE_FOLDER + ", " +
+                               ProviderMeta.ProviderTableMeta.UPLOADS_UPLOAD_END_TIMESTAMP + ", " +
+                               ProviderMeta.ProviderTableMeta.UPLOADS_LAST_RESULT + ", " +
+                               ProviderMeta.ProviderTableMeta.UPLOADS_IS_WHILE_CHARGING_ONLY + ", " +
+                               ProviderMeta.ProviderTableMeta.UPLOADS_IS_WIFI_ONLY + ", " +
+                               ProviderMeta.ProviderTableMeta.UPLOADS_CREATED_BY + ", " +
+                               ProviderMeta.ProviderTableMeta.UPLOADS_FOLDER_UNLOCK_TOKEN +
+                               " FROM " + tmpTableName);
+                db.execSQL("DROP TABLE " + tmpTableName);
+
+                upgraded = true;
+                db.setTransactionSuccessful();
+            } finally {
+                db.endTransaction();
+            }
+        }
+
+        if (!upgraded) {
+            Log_OC.i(TAG, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
+        }
+
+        if (oldVersion < 55 && newVersion >= 55) {
+            Log_OC.i(TAG, "Entering in the #55 add synced.name_collision_policy.");
+            db.beginTransaction();
+            try {
+                // Add synced.name_collision_policy
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.SYNCED_FOLDERS_TABLE_NAME +
+                               ADD_COLUMN + ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_NAME_COLLISION_POLICY + " INTEGER "); // integer
+
+                // make sure all existing folders set to FileUploader.NameCollisionPolicy.ASK_USER.
+                db.execSQL("UPDATE " + ProviderMeta.ProviderTableMeta.SYNCED_FOLDERS_TABLE_NAME + " SET " +
+                               ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_NAME_COLLISION_POLICY + " = " +
+                               NameCollisionPolicy.ASK_USER.serialize());
+                upgraded = true;
+                db.setTransactionSuccessful();
+            } finally {
+                db.endTransaction();
+            }
+        }
+
+        if (!upgraded) {
+            Log_OC.i(TAG, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
+        }
+
+        if (oldVersion < 56 && newVersion >= 56) {
+            Log_OC.i(TAG, "Entering in the #56 add decrypted remote path");
+            db.beginTransaction();
+            try {
+                // Add synced.name_collision_policy
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.FILE_TABLE_NAME +
+                               ADD_COLUMN + ProviderMeta.ProviderTableMeta.FILE_PATH_DECRYPTED + " TEXT "); // strin
+
+                upgraded = true;
+                db.setTransactionSuccessful();
+            } finally {
+                db.endTransaction();
+            }
+        }
+
+        if (!upgraded) {
+            Log_OC.i(TAG, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
+        }
+
+        if (oldVersion < 57 && newVersion >= 57) {
+            Log_OC.i(TAG, "Entering in the #57 add etag for capabilities");
+            db.beginTransaction();
+            try {
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.CAPABILITIES_TABLE_NAME +
+                               ADD_COLUMN + ProviderMeta.ProviderTableMeta.CAPABILITIES_ETAG + " TEXT ");
+
+                upgraded = true;
+                db.setTransactionSuccessful();
+            } finally {
+                db.endTransaction();
+            }
+        }
+
+        if (!upgraded) {
+            Log_OC.i(TAG, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
+        }
+
+        if (oldVersion < 58 && newVersion >= 58) {
+            Log_OC.i(TAG, "Entering in the #58 add public link to share table");
+            db.beginTransaction();
+            try {
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.OCSHARES_TABLE_NAME +
+                               ADD_COLUMN + ProviderMeta.ProviderTableMeta.OCSHARES_SHARE_LINK + " TEXT ");
+
+                upgraded = true;
+                db.setTransactionSuccessful();
+            } finally {
+                db.endTransaction();
+            }
+        }
+
+        if (!upgraded) {
+            Log_OC.i(TAG, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
+        }
+
+        if (oldVersion < 59 && newVersion >= 59) {
+            Log_OC.i(TAG, "Entering in the #59 add public label to share table");
+            db.beginTransaction();
+            try {
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.OCSHARES_TABLE_NAME +
+                               ADD_COLUMN + ProviderMeta.ProviderTableMeta.OCSHARES_SHARE_LABEL + " TEXT ");
+
+                upgraded = true;
+                db.setTransactionSuccessful();
+            } finally {
+                db.endTransaction();
+            }
+        }
+
+        if (!upgraded) {
+            Log_OC.i(TAG, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
+        }
+
+        if (oldVersion < 60 && newVersion >= 60) {
+            Log_OC.i(TAG, "Entering in the #60 add user status to capability table");
+            db.beginTransaction();
+            try {
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.CAPABILITIES_TABLE_NAME +
+                               ADD_COLUMN + ProviderMeta.ProviderTableMeta.CAPABILITIES_USER_STATUS + " INTEGER ");
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.CAPABILITIES_TABLE_NAME +
+                               ADD_COLUMN + ProviderMeta.ProviderTableMeta.CAPABILITIES_USER_STATUS_SUPPORTS_EMOJI + " INTEGER ");
+
+                upgraded = true;
+                db.setTransactionSuccessful();
+            } finally {
+                db.endTransaction();
+            }
+        }
+
+        if (!upgraded) {
+            Log_OC.i(TAG, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
+        }
+
+        if (oldVersion < 61 && newVersion >= 61) {
+            Log_OC.i(TAG, "Entering in the #61 reset eTag to force capability refresh");
+            db.beginTransaction();
+            try {
+                db.execSQL("UPDATE capabilities SET etag = '' WHERE 1=1");
+
+                upgraded = true;
+                db.setTransactionSuccessful();
+            } finally {
+                db.endTransaction();
+            }
+        }
+
+        if (!upgraded) {
+            Log_OC.i(TAG, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
+        }
+
+        if (oldVersion < 62 && newVersion >= 62) {
+            Log_OC.i(TAG, "Entering in the #62 add logo to capability");
+            db.beginTransaction();
+            try {
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.CAPABILITIES_TABLE_NAME +
+                               ADD_COLUMN + ProviderMeta.ProviderTableMeta.CAPABILITIES_SERVER_LOGO + " TEXT ");
+
+                // force refresh
+                db.execSQL("UPDATE capabilities SET etag = '' WHERE 1=1");
+
+                upgraded = true;
+                db.setTransactionSuccessful();
+            } finally {
+                db.endTransaction();
+            }
+        }
+
+        if (oldVersion < 63 && newVersion >= 63) {
+            Log_OC.i(TAG, "Adding file locking columns");
+            db.beginTransaction();
+            try {
+                // locking capabilities
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.CAPABILITIES_TABLE_NAME + ADD_COLUMN + ProviderMeta.ProviderTableMeta.CAPABILITIES_FILES_LOCKING_VERSION + " TEXT ");
+                // force refresh
+                db.execSQL("UPDATE capabilities SET etag = '' WHERE 1=1");
+                // locking properties
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.FILE_TABLE_NAME +
+                               ADD_COLUMN + ProviderMeta.ProviderTableMeta.FILE_LOCKED + " INTEGER "); // boolean
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.FILE_TABLE_NAME +
+                               ADD_COLUMN + ProviderMeta.ProviderTableMeta.FILE_LOCK_TYPE + " INTEGER ");
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.FILE_TABLE_NAME +
+                               ADD_COLUMN + ProviderMeta.ProviderTableMeta.FILE_LOCK_OWNER + " TEXT ");
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.FILE_TABLE_NAME +
+                               ADD_COLUMN + ProviderMeta.ProviderTableMeta.FILE_LOCK_OWNER_DISPLAY_NAME + " TEXT ");
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.FILE_TABLE_NAME +
+                               ADD_COLUMN + ProviderMeta.ProviderTableMeta.FILE_LOCK_OWNER_EDITOR + " TEXT ");
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.FILE_TABLE_NAME +
+                               ADD_COLUMN + ProviderMeta.ProviderTableMeta.FILE_LOCK_TIMESTAMP + " INTEGER ");
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.FILE_TABLE_NAME +
+                               ADD_COLUMN + ProviderMeta.ProviderTableMeta.FILE_LOCK_TIMEOUT + " INTEGER ");
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.FILE_TABLE_NAME +
+                               ADD_COLUMN + ProviderMeta.ProviderTableMeta.FILE_LOCK_TOKEN + " TEXT ");
+                db.execSQL("UPDATE " + ProviderMeta.ProviderTableMeta.FILE_TABLE_NAME + " SET " + ProviderMeta.ProviderTableMeta.FILE_ETAG + " = '' WHERE 1=1");
+
+                db.setTransactionSuccessful();
+            } finally {
+                db.endTransaction();
+            }
+        }
+
+        if (!upgraded) {
+            Log_OC.i(TAG, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
+        }
+
+        if (oldVersion < 64 && newVersion >= 64) {
+            Log_OC.i(TAG, "Entering in the #64 add metadata size to files");
+            db.beginTransaction();
+            try {
+                db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.FILE_TABLE_NAME +
+                               ADD_COLUMN + ProviderMeta.ProviderTableMeta.FILE_METADATA_SIZE + " TEXT ");
+
+                upgraded = true;
+                db.setTransactionSuccessful();
+            } finally {
+                db.endTransaction();
+            }
+        }
+
+        if (!upgraded) {
+            Log_OC.i(TAG, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
+        }
+    }
+
+    private void createOCSharesTable(SupportSQLiteDatabase db) {
+        db.execSQL("CREATE TABLE " + ProviderMeta.ProviderTableMeta.OCSHARES_TABLE_NAME + "("
+                       + ProviderMeta.ProviderTableMeta._ID + " INTEGER PRIMARY KEY, "
+                       + ProviderMeta.ProviderTableMeta.OCSHARES_FILE_SOURCE + INTEGER
+                       + ProviderMeta.ProviderTableMeta.OCSHARES_ITEM_SOURCE + INTEGER
+                       + ProviderMeta.ProviderTableMeta.OCSHARES_SHARE_TYPE + INTEGER
+                       + ProviderMeta.ProviderTableMeta.OCSHARES_SHARE_WITH + TEXT
+                       + ProviderMeta.ProviderTableMeta.OCSHARES_PATH + TEXT
+                       + ProviderMeta.ProviderTableMeta.OCSHARES_PERMISSIONS + INTEGER
+                       + ProviderMeta.ProviderTableMeta.OCSHARES_SHARED_DATE + INTEGER
+                       + ProviderMeta.ProviderTableMeta.OCSHARES_EXPIRATION_DATE + INTEGER
+                       + ProviderMeta.ProviderTableMeta.OCSHARES_TOKEN + TEXT
+                       + ProviderMeta.ProviderTableMeta.OCSHARES_SHARE_WITH_DISPLAY_NAME + TEXT
+                       + ProviderMeta.ProviderTableMeta.OCSHARES_IS_DIRECTORY + INTEGER  // boolean
+                       + ProviderMeta.ProviderTableMeta.OCSHARES_USER_ID + INTEGER
+                       + ProviderMeta.ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED + INTEGER
+                       + ProviderMeta.ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + TEXT
+                       + ProviderMeta.ProviderTableMeta.OCSHARES_IS_PASSWORD_PROTECTED + INTEGER
+                       + ProviderMeta.ProviderTableMeta.OCSHARES_NOTE + TEXT
+                       + ProviderMeta.ProviderTableMeta.OCSHARES_HIDE_DOWNLOAD + INTEGER
+                       + ProviderMeta.ProviderTableMeta.OCSHARES_SHARE_LINK + TEXT
+                       + ProviderMeta.ProviderTableMeta.OCSHARES_SHARE_LABEL + " TEXT );");
+    }
+
+    private void createCapabilitiesTable(SupportSQLiteDatabase db) {
+        db.execSQL("CREATE TABLE " + ProviderMeta.ProviderTableMeta.CAPABILITIES_TABLE_NAME + "("
+                       + ProviderMeta.ProviderTableMeta._ID + " INTEGER PRIMARY KEY, "
+                       + ProviderMeta.ProviderTableMeta.CAPABILITIES_ACCOUNT_NAME + TEXT
+                       + ProviderMeta.ProviderTableMeta.CAPABILITIES_VERSION_MAYOR + INTEGER
+                       + ProviderMeta.ProviderTableMeta.CAPABILITIES_VERSION_MINOR + INTEGER
+                       + ProviderMeta.ProviderTableMeta.CAPABILITIES_VERSION_MICRO + INTEGER
+                       + ProviderMeta.ProviderTableMeta.CAPABILITIES_VERSION_STRING + TEXT
+                       + ProviderMeta.ProviderTableMeta.CAPABILITIES_VERSION_EDITION + TEXT
+                       + ProviderMeta.ProviderTableMeta.CAPABILITIES_EXTENDED_SUPPORT + INTEGER
+                       + ProviderMeta.ProviderTableMeta.CAPABILITIES_CORE_POLLINTERVAL + INTEGER
+                       + ProviderMeta.ProviderTableMeta.CAPABILITIES_SHARING_API_ENABLED + INTEGER // boolean
+                       + ProviderMeta.ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_ENABLED + INTEGER  // boolean
+                       + ProviderMeta.ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_PASSWORD_ENFORCED + INTEGER    // boolean
+                       + ProviderMeta.ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_EXPIRE_DATE_ENABLED + INTEGER  // boolean
+                       + ProviderMeta.ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_EXPIRE_DATE_DAYS + INTEGER
+                       + ProviderMeta.ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_EXPIRE_DATE_ENFORCED + INTEGER // boolean
+                       + ProviderMeta.ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_SEND_MAIL + INTEGER    // boolean
+                       + ProviderMeta.ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_UPLOAD + INTEGER       // boolean
+                       + ProviderMeta.ProviderTableMeta.CAPABILITIES_SHARING_USER_SEND_MAIL + INTEGER      // boolean
+                       + ProviderMeta.ProviderTableMeta.CAPABILITIES_SHARING_RESHARING + INTEGER           // boolean
+                       + ProviderMeta.ProviderTableMeta.CAPABILITIES_SHARING_FEDERATION_OUTGOING + INTEGER     // boolean
+                       + ProviderMeta.ProviderTableMeta.CAPABILITIES_SHARING_FEDERATION_INCOMING + INTEGER     // boolean
+                       + ProviderMeta.ProviderTableMeta.CAPABILITIES_FILES_BIGFILECHUNKING + INTEGER   // boolean
+                       + ProviderMeta.ProviderTableMeta.CAPABILITIES_FILES_UNDELETE + INTEGER  // boolean
+                       + ProviderMeta.ProviderTableMeta.CAPABILITIES_FILES_VERSIONING + INTEGER   // boolean
+                       + ProviderMeta.ProviderTableMeta.CAPABILITIES_EXTERNAL_LINKS + INTEGER  // boolean
+                       + ProviderMeta.ProviderTableMeta.CAPABILITIES_SERVER_NAME + TEXT
+                       + ProviderMeta.ProviderTableMeta.CAPABILITIES_SERVER_COLOR + TEXT
+                       + ProviderMeta.ProviderTableMeta.CAPABILITIES_SERVER_TEXT_COLOR + TEXT
+                       + ProviderMeta.ProviderTableMeta.CAPABILITIES_SERVER_ELEMENT_COLOR + TEXT
+                       + ProviderMeta.ProviderTableMeta.CAPABILITIES_SERVER_SLOGAN + TEXT
+                       + ProviderMeta.ProviderTableMeta.CAPABILITIES_SERVER_LOGO + TEXT
+                       + ProviderMeta.ProviderTableMeta.CAPABILITIES_SERVER_BACKGROUND_URL + TEXT
+                       + ProviderMeta.ProviderTableMeta.CAPABILITIES_END_TO_END_ENCRYPTION + INTEGER
+                       + ProviderMeta.ProviderTableMeta.CAPABILITIES_ACTIVITY + INTEGER
+                       + ProviderMeta.ProviderTableMeta.CAPABILITIES_SERVER_BACKGROUND_DEFAULT + INTEGER
+                       + ProviderMeta.ProviderTableMeta.CAPABILITIES_SERVER_BACKGROUND_PLAIN + INTEGER
+                       + ProviderMeta.ProviderTableMeta.CAPABILITIES_RICHDOCUMENT + INTEGER
+                       + ProviderMeta.ProviderTableMeta.CAPABILITIES_RICHDOCUMENT_MIMETYPE_LIST + TEXT
+                       + ProviderMeta.ProviderTableMeta.CAPABILITIES_RICHDOCUMENT_DIRECT_EDITING + INTEGER
+                       + ProviderMeta.ProviderTableMeta.CAPABILITIES_RICHDOCUMENT_TEMPLATES + INTEGER
+                       + ProviderMeta.ProviderTableMeta.CAPABILITIES_RICHDOCUMENT_OPTIONAL_MIMETYPE_LIST + TEXT
+                       + ProviderMeta.ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_ASK_FOR_OPTIONAL_PASSWORD + INTEGER
+                       + ProviderMeta.ProviderTableMeta.CAPABILITIES_RICHDOCUMENT_PRODUCT_NAME + TEXT
+                       + ProviderMeta.ProviderTableMeta.CAPABILITIES_DIRECT_EDITING_ETAG + TEXT
+                       + ProviderMeta.ProviderTableMeta.CAPABILITIES_USER_STATUS + INTEGER
+                       + ProviderMeta.ProviderTableMeta.CAPABILITIES_USER_STATUS_SUPPORTS_EMOJI + INTEGER
+                       + ProviderMeta.ProviderTableMeta.CAPABILITIES_ETAG + TEXT
+                       + ProviderMeta.ProviderTableMeta.CAPABILITIES_FILES_LOCKING_VERSION + " TEXT );");
+    }
+
+    private void createUploadsTable(SupportSQLiteDatabase db) {
+        db.execSQL("CREATE TABLE " + ProviderMeta.ProviderTableMeta.UPLOADS_TABLE_NAME + "("
+                       + ProviderMeta.ProviderTableMeta._ID + " INTEGER PRIMARY KEY, "
+                       + ProviderMeta.ProviderTableMeta.UPLOADS_LOCAL_PATH + TEXT
+                       + ProviderMeta.ProviderTableMeta.UPLOADS_REMOTE_PATH + TEXT
+                       + ProviderMeta.ProviderTableMeta.UPLOADS_ACCOUNT_NAME + TEXT
+                       + ProviderMeta.ProviderTableMeta.UPLOADS_FILE_SIZE + " LONG, "
+                       + ProviderMeta.ProviderTableMeta.UPLOADS_STATUS + INTEGER               // UploadStatus
+                       + ProviderMeta.ProviderTableMeta.UPLOADS_LOCAL_BEHAVIOUR + INTEGER      // Upload LocalBehaviour
+                       + ProviderMeta.ProviderTableMeta.UPLOADS_UPLOAD_TIME + INTEGER
+                       + ProviderMeta.ProviderTableMeta.UPLOADS_NAME_COLLISION_POLICY + INTEGER  // boolean
+                       + ProviderMeta.ProviderTableMeta.UPLOADS_IS_CREATE_REMOTE_FOLDER + INTEGER  // boolean
+                       + ProviderMeta.ProviderTableMeta.UPLOADS_UPLOAD_END_TIMESTAMP + INTEGER
+                       + ProviderMeta.ProviderTableMeta.UPLOADS_LAST_RESULT + INTEGER     // Upload LastResult
+                       + ProviderMeta.ProviderTableMeta.UPLOADS_IS_WHILE_CHARGING_ONLY + INTEGER  // boolean
+                       + ProviderMeta.ProviderTableMeta.UPLOADS_IS_WIFI_ONLY + INTEGER // boolean
+                       + ProviderMeta.ProviderTableMeta.UPLOADS_CREATED_BY + INTEGER    // Upload createdBy
+                       + ProviderMeta.ProviderTableMeta.UPLOADS_FOLDER_UNLOCK_TOKEN + " TEXT );");
+
+    /* before:
+    // PRIMARY KEY should always imply NOT NULL. Unfortunately, due to a
+    // bug in some early versions, this is not the case in SQLite.
+    //db.execSQL("CREATE TABLE " + TABLE_UPLOAD + " (" + " path TEXT PRIMARY KEY NOT NULL UNIQUE,"
+    //        + " uploadStatus INTEGER NOT NULL, uploadObject TEXT NOT NULL);");
+    // uploadStatus is used to easy filtering, it has precedence over
+    // uploadObject.getUploadStatus()
+    */
+    }
+
+    private void createSyncedFoldersTable(SupportSQLiteDatabase db) {
+        db.execSQL("CREATE TABLE " + ProviderMeta.ProviderTableMeta.SYNCED_FOLDERS_TABLE_NAME + "("
+                       + ProviderMeta.ProviderTableMeta._ID + " INTEGER PRIMARY KEY, "                 // id
+                       + ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_LOCAL_PATH + " TEXT, "           // local path
+                       + ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_REMOTE_PATH + " TEXT, "          // remote path
+                       + ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_WIFI_ONLY + " INTEGER, "         // wifi_only
+                       + ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_CHARGING_ONLY + " INTEGER, "     // charging only
+                       + ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_EXISTING + " INTEGER, "          // existing
+                       + ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_ENABLED + " INTEGER, "           // enabled
+                       + ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_ENABLED_TIMESTAMP_MS + " INTEGER, " // enable date
+                       + ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_SUBFOLDER_BY_DATE + " INTEGER, " // subfolder by date
+                       + ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_ACCOUNT + "  TEXT, "             // account
+                       + ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_UPLOAD_ACTION + " INTEGER, "     // upload action
+                       + ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_NAME_COLLISION_POLICY + " INTEGER, " // name collision policy
+                       + ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_TYPE + " INTEGER, "              // type
+                       + ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_HIDDEN + " INTEGER );"           // hidden
+                  );
+    }
+
+    private void createExternalLinksTable(SupportSQLiteDatabase db) {
+        db.execSQL("CREATE TABLE " + ProviderMeta.ProviderTableMeta.EXTERNAL_LINKS_TABLE_NAME + "("
+                       + ProviderMeta.ProviderTableMeta._ID + " INTEGER PRIMARY KEY, "          // id
+                       + ProviderMeta.ProviderTableMeta.EXTERNAL_LINKS_ICON_URL + " TEXT, "     // icon url
+                       + ProviderMeta.ProviderTableMeta.EXTERNAL_LINKS_LANGUAGE + " TEXT, "     // language
+                       + ProviderMeta.ProviderTableMeta.EXTERNAL_LINKS_TYPE + " INTEGER, "      // type
+                       + ProviderMeta.ProviderTableMeta.EXTERNAL_LINKS_NAME + " TEXT, "         // name
+                       + ProviderMeta.ProviderTableMeta.EXTERNAL_LINKS_URL + " TEXT, "          // url
+                       + ProviderMeta.ProviderTableMeta.EXTERNAL_LINKS_REDIRECT + " INTEGER );" // redirect
+                  );
+    }
+
+    private void createArbitraryData(SupportSQLiteDatabase db) {
+        db.execSQL("CREATE TABLE " + ProviderMeta.ProviderTableMeta.ARBITRARY_DATA_TABLE_NAME + "("
+                       + ProviderMeta.ProviderTableMeta._ID + " INTEGER PRIMARY KEY, "      // id
+                       + ProviderMeta.ProviderTableMeta.ARBITRARY_DATA_CLOUD_ID + " TEXT, " // cloud id (account name + FQDN)
+                       + "'" + ProviderMeta.ProviderTableMeta.ARBITRARY_DATA_KEY + "'" + " TEXT, "      // key
+                       + ProviderMeta.ProviderTableMeta.ARBITRARY_DATA_VALUE + " TEXT );"   // value
+                  );
+    }
+
+    private void createVirtualTable(SupportSQLiteDatabase db) {
+        db.execSQL("CREATE TABLE '" + ProviderMeta.ProviderTableMeta.VIRTUAL_TABLE_NAME + "' ("
+                       + ProviderMeta.ProviderTableMeta._ID + " INTEGER PRIMARY KEY, "          // id
+                       + ProviderMeta.ProviderTableMeta.VIRTUAL_TYPE + " TEXT, "                // type
+                       + ProviderMeta.ProviderTableMeta.VIRTUAL_OCFILE_ID + " INTEGER )"        // file id
+                  );
+    }
+
+    private void createFileSystemTable(SupportSQLiteDatabase db) {
+        db.execSQL("CREATE TABLE IF NOT EXISTS " + ProviderMeta.ProviderTableMeta.FILESYSTEM_TABLE_NAME + "("
+                       + ProviderMeta.ProviderTableMeta._ID + " INTEGER PRIMARY KEY, "      // id
+                       + ProviderMeta.ProviderTableMeta.FILESYSTEM_FILE_LOCAL_PATH + " TEXT, "
+                       + ProviderMeta.ProviderTableMeta.FILESYSTEM_FILE_IS_FOLDER + " INTEGER, "
+                       + ProviderMeta.ProviderTableMeta.FILESYSTEM_FILE_FOUND_RECENTLY + " LONG, "
+                       + ProviderMeta.ProviderTableMeta.FILESYSTEM_FILE_SENT_FOR_UPLOAD + " INTEGER, "
+                       + ProviderMeta.ProviderTableMeta.FILESYSTEM_SYNCED_FOLDER_ID + " STRING, "
+                       + ProviderMeta.ProviderTableMeta.FILESYSTEM_CRC32 + " STRING, "
+                       + ProviderMeta.ProviderTableMeta.FILESYSTEM_FILE_MODIFIED + " LONG );"
+                  );
+    }
+
+    private boolean checkIfColumnExists(SupportSQLiteDatabase database, String table, String column) {
+        Cursor cursor = database.query("SELECT * FROM " + table + " LIMIT 0");
+        boolean exists = cursor.getColumnIndex(column) != -1;
+        cursor.close();
+
+        return exists;
+    }
+
+
+    /**
+     * Version 10 of database does not modify its scheme. It coincides with the upgrade of the ownCloud account names
+     * structure to include in it the path to the server instance. Updating the account names and path to local files in
+     * the files table is a must to keep the existing account working and the database clean.
+     *
+     * @param db Database where table of files is included.
+     */
+    private void updateAccountName(SupportSQLiteDatabase db) {
+        Log_OC.d(TAG, "THREAD:  " + Thread.currentThread().getName());
+        AccountManager ama = AccountManager.get(context);
+        try {
+            // get accounts from AccountManager ;  we can't be sure if accounts in it are updated or not although
+            // we know the update was previously done in {link @FileActivity#onCreate} because the changes through
+            // AccountManager are not synchronous
+            Account[] accounts = AccountManager.get(context).getAccountsByType(MainApp.getAccountType(context));
+            String serverUrl;
+            String username;
+            String oldAccountName;
+            String newAccountName;
+            String[] accountOwner = new String[1];
+
+            for (Account account : accounts) {
+                // build both old and new account name
+                serverUrl = ama.getUserData(account, AccountUtils.Constants.KEY_OC_BASE_URL);
+                username = AccountUtils.getUsernameForAccount(account);
+                oldAccountName = AccountUtils.buildAccountNameOld(Uri.parse(serverUrl), username);
+                newAccountName = AccountUtils.buildAccountName(Uri.parse(serverUrl), username);
+
+                // update values in database
+                db.beginTransaction();
+                try {
+                    ContentValues cv = new ContentValues();
+                    cv.put(ProviderMeta.ProviderTableMeta.FILE_ACCOUNT_OWNER, newAccountName);
+                    accountOwner[0] = oldAccountName;
+                    int num = db.update(ProviderMeta.ProviderTableMeta.FILE_TABLE_NAME,
+                                        SQLiteDatabase.CONFLICT_REPLACE,
+                                        cv,
+                                        ProviderMeta.ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?",
+                                        accountOwner);
+
+                    Log_OC.d(TAG, "Updated account in database: old name == " + oldAccountName +
+                        ", new name == " + newAccountName + " (" + num + " rows updated )");
+
+                    // update path for downloaded files
+                    updateDownloadedFiles(db, newAccountName, oldAccountName);
+
+                    db.setTransactionSuccessful();
+
+                } catch (SQLException e) {
+                    Log_OC.e(TAG, "SQL Exception upgrading account names or paths in database", e);
+                } finally {
+                    db.endTransaction();
+                }
+            }
+        } catch (Exception e) {
+            Log_OC.e(TAG, "Exception upgrading account names or paths in database", e);
+        }
+    }
+
+    /**
+     * Rename the local ownCloud folder of one account to match the a rename of the account itself. Updates the table of
+     * files in database so that the paths to the local files keep being the same.
+     *
+     * @param db             Database where table of files is included.
+     * @param newAccountName New name for the target OC account.
+     * @param oldAccountName Old name of the target OC account.
+     */
+    private void updateDownloadedFiles(SupportSQLiteDatabase db, String newAccountName,
+                                       String oldAccountName) {
+
+        String whereClause = ProviderMeta.ProviderTableMeta.FILE_ACCOUNT_OWNER + "=? AND " +
+            ProviderMeta.ProviderTableMeta.FILE_STORAGE_PATH + " IS NOT NULL";
+
+        final SupportSQLiteQuery query = SupportSQLiteQueryBuilder.builder(ProviderMeta.ProviderTableMeta.FILE_TABLE_NAME)
+            .columns(PROJECTION_FILE_AND_STORAGE_PATH)
+            .selection(whereClause, new String[]{newAccountName})
+            .create();
+
+        Cursor c = db.query(query);
+
+        try {
+            if (c.moveToFirst()) {
+                // create storage path
+                String oldAccountPath = FileStorageUtils.getSavePath(oldAccountName);
+                String newAccountPath = FileStorageUtils.getSavePath(newAccountName);
+
+                // move files
+                File oldAccountFolder = new File(oldAccountPath);
+                File newAccountFolder = new File(newAccountPath);
+                oldAccountFolder.renameTo(newAccountFolder);
+
+                String[] storagePath = new String[1];
+
+                // update database
+                do {
+                    // Update database
+                    String oldPath = c.getString(
+                        c.getColumnIndexOrThrow(ProviderMeta.ProviderTableMeta.FILE_STORAGE_PATH));
+                    OCFile file = new OCFile(
+                        c.getString(c.getColumnIndexOrThrow(ProviderMeta.ProviderTableMeta.FILE_PATH)));
+                    String newPath = FileStorageUtils.getDefaultSavePathFor(newAccountName, file);
+
+                    ContentValues cv = new ContentValues();
+                    cv.put(ProviderMeta.ProviderTableMeta.FILE_STORAGE_PATH, newPath);
+                    storagePath[0] = oldPath;
+                    db.update(ProviderMeta.ProviderTableMeta.FILE_TABLE_NAME,
+                              SQLiteDatabase.CONFLICT_REPLACE,
+                              cv,
+                              ProviderMeta.ProviderTableMeta.FILE_STORAGE_PATH + "=?",
+                              storagePath);
+
+                    Log_OC.v(TAG, "Updated path of downloaded file: old file name == " + oldPath +
+                        ", new file name == " + newPath);
+
+                } while (c.moveToNext());
+            }
+        } finally {
+            c.close();
+        }
+    }
+
+}

+ 105 - 12
app/src/main/java/com/nextcloud/client/database/NextcloudDatabase.kt

@@ -22,8 +22,12 @@
 
 package com.nextcloud.client.database
 
+import android.content.Context
 import androidx.room.Database
 import androidx.room.RoomDatabase
+import androidx.room.migration.Migration
+import androidx.sqlite.db.SupportSQLiteDatabase
+import com.nextcloud.client.core.Clock
 import com.nextcloud.client.database.entity.ArbitraryDataEntity
 import com.nextcloud.client.database.entity.CapabilityEntity
 import com.nextcloud.client.database.entity.ExternalLinkEntity
@@ -50,16 +54,105 @@ import com.owncloud.android.db.ProviderMeta
     version = ProviderMeta.DB_VERSION
 )
 abstract class NextcloudDatabase : RoomDatabase() {
-    // companion object {
-    //     val MIGRATION_1_64 = object : Migration(1, 64) {
-    //         override fun migrate(database: SupportSQLiteDatabase) {
-    //             TODO("Not yet implemented, use legacy migrations")
-    //         }
-    //     }
-    //     val MIGRATION_64_65 = object : Migration(64, 65) {
-    //         override fun migrate(database: SupportSQLiteDatabase) {
-    //             // this is just for Room compatibility. No need for any migration
-    //         }
-    //     }
-    // }
+
+    // migrations from before Room was introduced
+    private class LegacyMigration(
+        private val from: Int,
+        private val to: Int,
+        private val context: Context,
+        private val clock: Clock
+    ) :
+        Migration(from, to) {
+        override fun migrate(database: SupportSQLiteDatabase) {
+            LegacyMigrationHelper(context, clock)
+                .onUpgrade(database, from, to)
+        }
+    }
+
+    companion object {
+        private const val FIRST_ROOM_DB_VERSION = 65
+
+        @JvmField
+        val roomMigration = object : Migration(FIRST_ROOM_DB_VERSION - 1, FIRST_ROOM_DB_VERSION) {
+            override fun migrate(database: SupportSQLiteDatabase) {
+                // migrate LONG, STRING to INTEGER, TEXT
+                migrateFilesystemTable(database)
+                migrateUploadsTable(database)
+            }
+
+            private fun migrateFilesystemTable(database: SupportSQLiteDatabase) {
+                val table = "filesystem"
+                val newTable = "${table}_new"
+                // create table with fixed types
+                database.execSQL(
+                    "CREATE TABLE $newTable (" +
+                        "_id INTEGER PRIMARY KEY," +
+                        "local_path TEXT," +
+                        "is_folder INTEGER," +
+                        "found_at INTEGER," +
+                        "upload_triggered INTEGER," +
+                        "syncedfolder_id TEXT," +
+                        "crc32 TEXT," +
+                        "modified_at INTEGER " +
+                        ")"
+                )
+                // copy data
+                val columns =
+                    "_id, local_path, is_folder, found_at, upload_triggered, syncedfolder_id, crc32, modified_at"
+                database.execSQL(
+                    "INSERT INTO $newTable ($columns) " +
+                        "SELECT $columns FROM $table"
+                )
+                // replace table
+                database.execSQL("DROP TABLE $table")
+                database.execSQL("ALTER TABLE $newTable RENAME TO $table")
+            }
+
+            private fun migrateUploadsTable(database: SupportSQLiteDatabase) {
+                val table = "list_of_uploads"
+                val newTable = "${table}_new"
+                // create table with fixed types
+                database.execSQL(
+                    "CREATE TABLE $newTable (" +
+                        "_id INTEGER PRIMARY KEY," +
+                        "local_path TEXT, " +
+                        "remote_path TEXT, " +
+                        "account_name TEXT, " +
+                        "file_size INTEGER, " +
+                        "status INTEGER, " +
+                        "local_behaviour INTEGER, " +
+                        "upload_time INTEGER, " +
+                        "name_collision_policy INTEGER, " +
+                        "is_create_remote_folder INTEGER, " +
+                        "upload_end_timestamp INTEGER, " +
+                        "last_result INTEGER, " +
+                        "is_while_charging_only INTEGER, " +
+                        "is_wifi_only INTEGER, " +
+                        "created_by INTEGER, " +
+                        "folder_unlock_token TEXT " +
+                        ")"
+                )
+
+                // copy data
+                val columns =
+                    "_id, local_path, remote_path, account_name, file_size, status, local_behaviour, upload_time," +
+                        " name_collision_policy, is_create_remote_folder, upload_end_timestamp, last_result," +
+                        " is_while_charging_only, is_wifi_only, created_by, folder_unlock_token"
+                database.execSQL(
+                    "INSERT INTO $newTable ($columns) " +
+                        "SELECT $columns FROM $table"
+                )
+                // replace table
+                database.execSQL("DROP TABLE $table")
+                database.execSQL("ALTER TABLE $newTable RENAME TO $table")
+            }
+        }
+
+        @JvmStatic
+        fun getLegacyMigrations(context: Context, clock: Clock): Array<Migration> {
+            // no way to get old and new version inside the migration so we need to replicate it for every version bump
+            return (1 until FIRST_ROOM_DB_VERSION - 1)
+                .map { from -> LegacyMigration(from, from + 1, context, clock) }.toTypedArray()
+        }
+    }
 }

+ 1 - 1
app/src/main/java/com/nextcloud/client/database/entity/ArbitraryDataEntity.kt

@@ -31,7 +31,7 @@ import com.owncloud.android.db.ProviderMeta.ProviderTableMeta
 data class ArbitraryDataEntity(
     @PrimaryKey(autoGenerate = true)
     @ColumnInfo(name = ProviderTableMeta._ID)
-    val id: Int,
+    val id: Int?,
     @ColumnInfo(name = ProviderTableMeta.ARBITRARY_DATA_CLOUD_ID)
     val cloudId: String?,
     @ColumnInfo(name = ProviderTableMeta.ARBITRARY_DATA_KEY)

+ 32 - 32
app/src/main/java/com/nextcloud/client/database/entity/CapabilityEntity.kt

@@ -31,55 +31,55 @@ import com.owncloud.android.db.ProviderMeta.ProviderTableMeta
 data class CapabilityEntity(
     @PrimaryKey(autoGenerate = true)
     @ColumnInfo(name = ProviderTableMeta._ID)
-    val id: Int,
+    val id: Int?,
     @ColumnInfo(name = ProviderTableMeta.CAPABILITIES_ACCOUNT_NAME)
     val accountName: String?,
     @ColumnInfo(name = ProviderTableMeta.CAPABILITIES_VERSION_MAYOR)
-    val versionMajor: Int,
+    val versionMajor: Int?,
     @ColumnInfo(name = ProviderTableMeta.CAPABILITIES_VERSION_MINOR)
-    val versionMinor: Int,
+    val versionMinor: Int?,
     @ColumnInfo(name = ProviderTableMeta.CAPABILITIES_VERSION_MICRO)
-    val versionMicro: Int,
+    val versionMicro: Int?,
     @ColumnInfo(name = ProviderTableMeta.CAPABILITIES_VERSION_STRING)
     val versionString: String?,
     @ColumnInfo(name = ProviderTableMeta.CAPABILITIES_VERSION_EDITION)
     val versionEditor: String?,
     @ColumnInfo(name = ProviderTableMeta.CAPABILITIES_EXTENDED_SUPPORT)
-    val extendedSupport: Int,
+    val extendedSupport: Int?,
     @ColumnInfo(name = ProviderTableMeta.CAPABILITIES_CORE_POLLINTERVAL)
-    val corePollinterval: Int,
+    val corePollinterval: Int?,
     @ColumnInfo(name = ProviderTableMeta.CAPABILITIES_SHARING_API_ENABLED)
-    val sharingApiEnabled: Int,
+    val sharingApiEnabled: Int?,
     @ColumnInfo(name = ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_ENABLED)
-    val sharingPublicEnabled: Int,
+    val sharingPublicEnabled: Int?,
     @ColumnInfo(name = ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_PASSWORD_ENFORCED)
-    val sharingPublicPasswordEnforced: Int,
+    val sharingPublicPasswordEnforced: Int?,
     @ColumnInfo(name = ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_EXPIRE_DATE_ENABLED)
-    val sharingPublicExpireDateEnabled: Int,
+    val sharingPublicExpireDateEnabled: Int?,
     @ColumnInfo(name = ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_EXPIRE_DATE_DAYS)
-    val sharingPublicExpireDateDays: Int,
+    val sharingPublicExpireDateDays: Int?,
     @ColumnInfo(name = ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_EXPIRE_DATE_ENFORCED)
-    val sharingPublicExpireDateEnforced: Int,
+    val sharingPublicExpireDateEnforced: Int?,
     @ColumnInfo(name = ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_SEND_MAIL)
-    val sharingPublicSendMail: Int,
+    val sharingPublicSendMail: Int?,
     @ColumnInfo(name = ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_UPLOAD)
-    val sharingPublicUpload: Int,
+    val sharingPublicUpload: Int?,
     @ColumnInfo(name = ProviderTableMeta.CAPABILITIES_SHARING_USER_SEND_MAIL)
-    val sharingUserSendMail: Int,
+    val sharingUserSendMail: Int?,
     @ColumnInfo(name = ProviderTableMeta.CAPABILITIES_SHARING_RESHARING)
-    val sharingResharing: Int,
+    val sharingResharing: Int?,
     @ColumnInfo(name = ProviderTableMeta.CAPABILITIES_SHARING_FEDERATION_OUTGOING)
-    val sharingFederationOutgoing: Int,
+    val sharingFederationOutgoing: Int?,
     @ColumnInfo(name = ProviderTableMeta.CAPABILITIES_SHARING_FEDERATION_INCOMING)
-    val sharingFederationIncoming: Int,
+    val sharingFederationIncoming: Int?,
     @ColumnInfo(name = ProviderTableMeta.CAPABILITIES_FILES_BIGFILECHUNKING)
-    val filesBigfilechunking: Int,
+    val filesBigfilechunking: Int?,
     @ColumnInfo(name = ProviderTableMeta.CAPABILITIES_FILES_UNDELETE)
-    val filesUndelete: Int,
+    val filesUndelete: Int?,
     @ColumnInfo(name = ProviderTableMeta.CAPABILITIES_FILES_VERSIONING)
-    val filesVersioning: Int,
+    val filesVersioning: Int?,
     @ColumnInfo(name = ProviderTableMeta.CAPABILITIES_EXTERNAL_LINKS)
-    val externalLinks: Int,
+    val externalLinks: Int?,
     @ColumnInfo(name = ProviderTableMeta.CAPABILITIES_SERVER_NAME)
     val serverName: String?,
     @ColumnInfo(name = ProviderTableMeta.CAPABILITIES_SERVER_COLOR)
@@ -95,33 +95,33 @@ data class CapabilityEntity(
     @ColumnInfo(name = ProviderTableMeta.CAPABILITIES_SERVER_BACKGROUND_URL)
     val serverBackgroundUrl: String?,
     @ColumnInfo(name = ProviderTableMeta.CAPABILITIES_END_TO_END_ENCRYPTION)
-    val endToEndEncryption: Int,
+    val endToEndEncryption: Int?,
     @ColumnInfo(name = ProviderTableMeta.CAPABILITIES_ACTIVITY)
-    val activity: Int,
+    val activity: Int?,
     @ColumnInfo(name = ProviderTableMeta.CAPABILITIES_SERVER_BACKGROUND_DEFAULT)
-    val serverBackgroundDefault: Int,
+    val serverBackgroundDefault: Int?,
     @ColumnInfo(name = ProviderTableMeta.CAPABILITIES_SERVER_BACKGROUND_PLAIN)
-    val serverBackgroundPlain: Int,
+    val serverBackgroundPlain: Int?,
     @ColumnInfo(name = ProviderTableMeta.CAPABILITIES_RICHDOCUMENT)
-    val richdocument: Int,
+    val richdocument: Int?,
     @ColumnInfo(name = ProviderTableMeta.CAPABILITIES_RICHDOCUMENT_MIMETYPE_LIST)
     val richdocumentMimetypeList: String?,
     @ColumnInfo(name = ProviderTableMeta.CAPABILITIES_RICHDOCUMENT_DIRECT_EDITING)
-    val richdocumentDirectEditing: Int,
+    val richdocumentDirectEditing: Int?,
     @ColumnInfo(name = ProviderTableMeta.CAPABILITIES_RICHDOCUMENT_TEMPLATES)
-    val richdocumentTemplates: Int,
+    val richdocumentTemplates: Int?,
     @ColumnInfo(name = ProviderTableMeta.CAPABILITIES_RICHDOCUMENT_OPTIONAL_MIMETYPE_LIST)
     val richdocumentOptionalMimetypeList: String?,
     @ColumnInfo(name = ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_ASK_FOR_OPTIONAL_PASSWORD)
-    val sharingPublicAskForOptionalPassword: Int,
+    val sharingPublicAskForOptionalPassword: Int?,
     @ColumnInfo(name = ProviderTableMeta.CAPABILITIES_RICHDOCUMENT_PRODUCT_NAME)
     val richdocumentProductName: String?,
     @ColumnInfo(name = ProviderTableMeta.CAPABILITIES_DIRECT_EDITING_ETAG)
     val directEditingEtag: String?,
     @ColumnInfo(name = ProviderTableMeta.CAPABILITIES_USER_STATUS)
-    val userStatus: Int,
+    val userStatus: Int?,
     @ColumnInfo(name = ProviderTableMeta.CAPABILITIES_USER_STATUS_SUPPORTS_EMOJI)
-    val userStatusSupportsEmoji: Int,
+    val userStatusSupportsEmoji: Int?,
     @ColumnInfo(name = ProviderTableMeta.CAPABILITIES_ETAG)
     val etag: String?,
     @ColumnInfo(name = ProviderTableMeta.CAPABILITIES_FILES_LOCKING_VERSION)

+ 4 - 4
app/src/main/java/com/nextcloud/client/database/entity/ExternalLinkEntity.kt

@@ -31,17 +31,17 @@ import com.owncloud.android.db.ProviderMeta.ProviderTableMeta
 data class ExternalLinkEntity(
     @PrimaryKey(autoGenerate = true)
     @ColumnInfo(name = ProviderTableMeta._ID)
-    val id: Int,
+    val id: Int?,
     @ColumnInfo(name = ProviderTableMeta.EXTERNAL_LINKS_ICON_URL)
     val iconUrl: String?,
     @ColumnInfo(name = ProviderTableMeta.EXTERNAL_LINKS_LANGUAGE)
     val language: String?,
     @ColumnInfo(name = ProviderTableMeta.EXTERNAL_LINKS_TYPE)
-    val type: Int,
+    val type: Int?,
     @ColumnInfo(name = ProviderTableMeta.EXTERNAL_LINKS_NAME)
     val name: String?,
     @ColumnInfo(name = ProviderTableMeta.EXTERNAL_LINKS_URL)
-    val url: String,
+    val url: String?,
     @ColumnInfo(name = ProviderTableMeta.EXTERNAL_LINKS_REDIRECT)
-    val redirect: Int
+    val redirect: Int?
 )

+ 20 - 20
app/src/main/java/com/nextcloud/client/database/entity/FileEntity.kt

@@ -31,7 +31,7 @@ import com.owncloud.android.db.ProviderMeta.ProviderTableMeta
 data class FileEntity(
     @PrimaryKey(autoGenerate = true)
     @ColumnInfo(name = ProviderTableMeta._ID)
-    val id: Int,
+    val id: Int?,
     @ColumnInfo(name = ProviderTableMeta.FILE_NAME)
     val name: String?,
     @ColumnInfo(name = ProviderTableMeta.FILE_ENCRYPTED_NAME)
@@ -41,53 +41,53 @@ data class FileEntity(
     @ColumnInfo(name = ProviderTableMeta.FILE_PATH_DECRYPTED)
     val pathDecrypted: String?,
     @ColumnInfo(name = ProviderTableMeta.FILE_PARENT)
-    val parent: Int,
+    val parent: Int?,
     @ColumnInfo(name = ProviderTableMeta.FILE_CREATION)
-    val creation: Int,
+    val creation: Int?,
     @ColumnInfo(name = ProviderTableMeta.FILE_MODIFIED)
-    val modified: Int,
+    val modified: Int?,
     @ColumnInfo(name = ProviderTableMeta.FILE_CONTENT_TYPE)
     val contentType: String?,
     @ColumnInfo(name = ProviderTableMeta.FILE_CONTENT_LENGTH)
-    val contentLength: Int,
+    val contentLength: Int?,
     @ColumnInfo(name = ProviderTableMeta.FILE_STORAGE_PATH)
     val storagePath: String?,
     @ColumnInfo(name = ProviderTableMeta.FILE_ACCOUNT_OWNER)
     val accountOwner: String?,
     @ColumnInfo(name = ProviderTableMeta.FILE_LAST_SYNC_DATE)
-    val lastSyncDate: Int,
+    val lastSyncDate: Int?,
     @ColumnInfo(name = ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA)
-    val lastSyncDateForData: Int,
+    val lastSyncDateForData: Int?,
     @ColumnInfo(name = ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA)
-    val modifiedAtLastSyncForData: Int,
+    val modifiedAtLastSyncForData: Int?,
     @ColumnInfo(name = ProviderTableMeta.FILE_ETAG)
     val etag: String?,
     @ColumnInfo(name = ProviderTableMeta.FILE_ETAG_ON_SERVER)
     val etagOnServer: String?,
     @ColumnInfo(name = ProviderTableMeta.FILE_SHARED_VIA_LINK)
-    val sharedViaLink: Int,
+    val sharedViaLink: Int?,
     @ColumnInfo(name = ProviderTableMeta.FILE_PERMISSIONS)
     val permissions: String?,
     @ColumnInfo(name = ProviderTableMeta.FILE_REMOTE_ID)
     val remoteId: String?,
     @ColumnInfo(name = ProviderTableMeta.FILE_UPDATE_THUMBNAIL)
-    val updateThumbnail: Int,
+    val updateThumbnail: Int?,
     @ColumnInfo(name = ProviderTableMeta.FILE_IS_DOWNLOADING)
-    val isDownloading: Int,
+    val isDownloading: Int?,
     @ColumnInfo(name = ProviderTableMeta.FILE_FAVORITE)
-    val favorite: Int,
+    val favorite: Int?,
     @ColumnInfo(name = ProviderTableMeta.FILE_IS_ENCRYPTED)
-    val isEncrypted: Int,
+    val isEncrypted: Int?,
     @ColumnInfo(name = ProviderTableMeta.FILE_ETAG_IN_CONFLICT)
     val etagInConflict: String?,
     @ColumnInfo(name = ProviderTableMeta.FILE_SHARED_WITH_SHAREE)
-    val sharedWithSharee: Int,
+    val sharedWithSharee: Int?,
     @ColumnInfo(name = ProviderTableMeta.FILE_MOUNT_TYPE)
     val mountType: Int?,
     @ColumnInfo(name = ProviderTableMeta.FILE_HAS_PREVIEW)
-    val hasPreview: Int,
+    val hasPreview: Int?,
     @ColumnInfo(name = ProviderTableMeta.FILE_UNREAD_COMMENTS_COUNT)
-    val unreadCommentsCount: Int,
+    val unreadCommentsCount: Int?,
     @ColumnInfo(name = ProviderTableMeta.FILE_OWNER_ID)
     val ownerId: String?,
     @ColumnInfo(name = ProviderTableMeta.FILE_OWNER_DISPLAY_NAME)
@@ -101,9 +101,9 @@ data class FileEntity(
     @ColumnInfo(name = ProviderTableMeta.FILE_METADATA_SIZE)
     val metadataSize: String?,
     @ColumnInfo(name = ProviderTableMeta.FILE_LOCKED)
-    val locked: Int,
+    val locked: Int?,
     @ColumnInfo(name = ProviderTableMeta.FILE_LOCK_TYPE)
-    val lockType: Int,
+    val lockType: Int?,
     @ColumnInfo(name = ProviderTableMeta.FILE_LOCK_OWNER)
     val lockOwner: String?,
     @ColumnInfo(name = ProviderTableMeta.FILE_LOCK_OWNER_DISPLAY_NAME)
@@ -111,9 +111,9 @@ data class FileEntity(
     @ColumnInfo(name = ProviderTableMeta.FILE_LOCK_OWNER_EDITOR)
     val lockOwnerEditor: String?,
     @ColumnInfo(name = ProviderTableMeta.FILE_LOCK_TIMESTAMP)
-    val lockTimestamp: Int,
+    val lockTimestamp: Int?,
     @ColumnInfo(name = ProviderTableMeta.FILE_LOCK_TIMEOUT)
-    val lockTimeout: Int,
+    val lockTimeout: Int?,
     @ColumnInfo(name = ProviderTableMeta.FILE_LOCK_TOKEN)
     val lockToken: String?
 )

+ 5 - 5
app/src/main/java/com/nextcloud/client/database/entity/FilesystemEntity.kt

@@ -31,19 +31,19 @@ import com.owncloud.android.db.ProviderMeta.ProviderTableMeta
 data class FilesystemEntity(
     @PrimaryKey(autoGenerate = true)
     @ColumnInfo(name = ProviderTableMeta._ID)
-    val id: Int,
+    val id: Int?,
     @ColumnInfo(name = ProviderTableMeta.FILESYSTEM_FILE_LOCAL_PATH)
     val localPath: String?,
     @ColumnInfo(name = ProviderTableMeta.FILESYSTEM_FILE_IS_FOLDER)
-    val fileIsFolder: Int,
+    val fileIsFolder: Int?,
     @ColumnInfo(name = ProviderTableMeta.FILESYSTEM_FILE_FOUND_RECENTLY)
-    val fileFoundRecently: Long,
+    val fileFoundRecently: Long?,
     @ColumnInfo(name = ProviderTableMeta.FILESYSTEM_FILE_SENT_FOR_UPLOAD)
-    val fileSentForUpload: Int,
+    val fileSentForUpload: Int?,
     @ColumnInfo(name = ProviderTableMeta.FILESYSTEM_SYNCED_FOLDER_ID)
     val syncedFolderId: String?,
     @ColumnInfo(name = ProviderTableMeta.FILESYSTEM_CRC32)
     val crc32: String?,
     @ColumnInfo(name = ProviderTableMeta.FILESYSTEM_FILE_MODIFIED)
-    val fileModified: Long
+    val fileModified: Long?
 )

+ 12 - 12
app/src/main/java/com/nextcloud/client/database/entity/ShareEntity.kt

@@ -31,41 +31,41 @@ import com.owncloud.android.db.ProviderMeta.ProviderTableMeta
 data class ShareEntity(
     @PrimaryKey(autoGenerate = true)
     @ColumnInfo(name = ProviderTableMeta._ID)
-    val id: Int,
+    val id: Int?,
     @ColumnInfo(name = ProviderTableMeta.OCSHARES_FILE_SOURCE)
-    val fileSource: Int,
+    val fileSource: Int?,
     @ColumnInfo(name = ProviderTableMeta.OCSHARES_ITEM_SOURCE)
-    val itemSource: Int,
+    val itemSource: Int?,
     @ColumnInfo(name = ProviderTableMeta.OCSHARES_SHARE_TYPE)
-    val shareType: Int,
+    val shareType: Int?,
     @ColumnInfo(name = ProviderTableMeta.OCSHARES_SHARE_WITH)
     val shareWith: String?,
     @ColumnInfo(name = ProviderTableMeta.OCSHARES_PATH)
     val path: String?,
     @ColumnInfo(name = ProviderTableMeta.OCSHARES_PERMISSIONS)
-    val permissions: Int,
+    val permissions: Int?,
     @ColumnInfo(name = ProviderTableMeta.OCSHARES_SHARED_DATE)
-    val sharedDate: Int,
+    val sharedDate: Int?,
     @ColumnInfo(name = ProviderTableMeta.OCSHARES_EXPIRATION_DATE)
-    val expirationDate: Int,
+    val expirationDate: Int?,
     @ColumnInfo(name = ProviderTableMeta.OCSHARES_TOKEN)
     val token: String?,
     @ColumnInfo(name = ProviderTableMeta.OCSHARES_SHARE_WITH_DISPLAY_NAME)
     val shareWithDisplayName: String?,
     @ColumnInfo(name = ProviderTableMeta.OCSHARES_IS_DIRECTORY)
-    val isDirectory: Int,
+    val isDirectory: Int?,
     @ColumnInfo(name = ProviderTableMeta.OCSHARES_USER_ID)
-    val userId: Int,
+    val userId: Int?,
     @ColumnInfo(name = ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED)
-    val idRemoteShared: Int,
+    val idRemoteShared: Int?,
     @ColumnInfo(name = ProviderTableMeta.OCSHARES_ACCOUNT_OWNER)
     val accountOwner: String?,
     @ColumnInfo(name = ProviderTableMeta.OCSHARES_IS_PASSWORD_PROTECTED)
-    val isPasswordProtected: Int,
+    val isPasswordProtected: Int?,
     @ColumnInfo(name = ProviderTableMeta.OCSHARES_NOTE)
     val note: String?,
     @ColumnInfo(name = ProviderTableMeta.OCSHARES_HIDE_DOWNLOAD)
-    val hideDownload: Int,
+    val hideDownload: Int?,
     @ColumnInfo(name = ProviderTableMeta.OCSHARES_SHARE_LINK)
     val shareLink: String?,
     @ColumnInfo(name = ProviderTableMeta.OCSHARES_SHARE_LABEL)

+ 11 - 11
app/src/main/java/com/nextcloud/client/database/entity/SyncedFolderEntity.kt

@@ -31,31 +31,31 @@ import com.owncloud.android.db.ProviderMeta.ProviderTableMeta
 data class SyncedFolderEntity(
     @PrimaryKey(autoGenerate = true)
     @ColumnInfo(name = ProviderTableMeta._ID)
-    val id: Int,
+    val id: Int?,
     @ColumnInfo(name = ProviderTableMeta.SYNCED_FOLDER_LOCAL_PATH)
     val localPath: String?,
     @ColumnInfo(name = ProviderTableMeta.SYNCED_FOLDER_REMOTE_PATH)
     val remotePath: String?,
     @ColumnInfo(name = ProviderTableMeta.SYNCED_FOLDER_WIFI_ONLY)
-    val wifiOnly: Int,
+    val wifiOnly: Int?,
     @ColumnInfo(name = ProviderTableMeta.SYNCED_FOLDER_CHARGING_ONLY)
-    val chargingOnly: Int,
+    val chargingOnly: Int?,
     @ColumnInfo(name = ProviderTableMeta.SYNCED_FOLDER_EXISTING)
-    val existing: Int,
+    val existing: Int?,
     @ColumnInfo(name = ProviderTableMeta.SYNCED_FOLDER_ENABLED)
-    val enabled: Int,
+    val enabled: Int?,
     @ColumnInfo(name = ProviderTableMeta.SYNCED_FOLDER_ENABLED_TIMESTAMP_MS)
-    val enabledTimestampMs: Int,
+    val enabledTimestampMs: Int?,
     @ColumnInfo(name = ProviderTableMeta.SYNCED_FOLDER_SUBFOLDER_BY_DATE)
-    val subfolderByDate: Int,
+    val subfolderByDate: Int?,
     @ColumnInfo(name = ProviderTableMeta.SYNCED_FOLDER_ACCOUNT)
     val account: String?,
     @ColumnInfo(name = ProviderTableMeta.SYNCED_FOLDER_UPLOAD_ACTION)
-    val uploadAction: Int,
+    val uploadAction: Int?,
     @ColumnInfo(name = ProviderTableMeta.SYNCED_FOLDER_NAME_COLLISION_POLICY)
-    val nameCollisionPolicy: Int,
+    val nameCollisionPolicy: Int?,
     @ColumnInfo(name = ProviderTableMeta.SYNCED_FOLDER_TYPE)
-    val type: Int,
+    val type: Int?,
     @ColumnInfo(name = ProviderTableMeta.SYNCED_FOLDER_HIDDEN)
-    val hidden: Int
+    val hidden: Int?
 )

+ 8 - 8
app/src/main/java/com/nextcloud/client/database/entity/UploadEntity.kt

@@ -31,7 +31,7 @@ import com.owncloud.android.db.ProviderMeta.ProviderTableMeta
 data class UploadEntity(
     @PrimaryKey(autoGenerate = true)
     @ColumnInfo(name = ProviderTableMeta._ID)
-    val id: Int,
+    val id: Int?,
     @ColumnInfo(name = ProviderTableMeta.UPLOADS_LOCAL_PATH)
     val localPath: String?,
     @ColumnInfo(name = ProviderTableMeta.UPLOADS_REMOTE_PATH)
@@ -41,25 +41,25 @@ data class UploadEntity(
     @ColumnInfo(name = ProviderTableMeta.UPLOADS_FILE_SIZE)
     val fileSize: Long?,
     @ColumnInfo(name = ProviderTableMeta.UPLOADS_STATUS)
-    val status: Int,
+    val status: Int?,
     @ColumnInfo(name = ProviderTableMeta.UPLOADS_LOCAL_BEHAVIOUR)
-    val localBehaviour: Int,
+    val localBehaviour: Int?,
     @ColumnInfo(name = ProviderTableMeta.UPLOADS_UPLOAD_TIME)
     val uploadTime: Int?,
     @ColumnInfo(name = ProviderTableMeta.UPLOADS_NAME_COLLISION_POLICY)
-    val nameCollisionPolicy: Int,
+    val nameCollisionPolicy: Int?,
     @ColumnInfo(name = ProviderTableMeta.UPLOADS_IS_CREATE_REMOTE_FOLDER)
-    val isCreateRemoteFolder: Int,
+    val isCreateRemoteFolder: Int?,
     @ColumnInfo(name = ProviderTableMeta.UPLOADS_UPLOAD_END_TIMESTAMP)
     val uploadEndTimestamp: Int?,
     @ColumnInfo(name = ProviderTableMeta.UPLOADS_LAST_RESULT)
     val lastResult: Int?,
     @ColumnInfo(name = ProviderTableMeta.UPLOADS_IS_WHILE_CHARGING_ONLY)
-    val isWhileChargingOnly: Int,
+    val isWhileChargingOnly: Int?,
     @ColumnInfo(name = ProviderTableMeta.UPLOADS_IS_WIFI_ONLY)
-    val isWifiOnly: Int,
+    val isWifiOnly: Int?,
     @ColumnInfo(name = ProviderTableMeta.UPLOADS_CREATED_BY)
-    val createdBy: Int,
+    val createdBy: Int?,
     @ColumnInfo(name = ProviderTableMeta.UPLOADS_FOLDER_UNLOCK_TOKEN)
     val folderUnlockToken: String?
 )

+ 3 - 3
app/src/main/java/com/nextcloud/client/database/entity/VirtualEntity.kt

@@ -31,9 +31,9 @@ import com.owncloud.android.db.ProviderMeta.ProviderTableMeta
 data class VirtualEntity(
     @PrimaryKey(autoGenerate = true)
     @ColumnInfo(name = ProviderTableMeta._ID)
-    val id: Int,
+    val id: Int?,
     @ColumnInfo(name = ProviderTableMeta.VIRTUAL_TYPE)
-    val type: String,
+    val type: String?,
     @ColumnInfo(name = ProviderTableMeta.VIRTUAL_OCFILE_ID)
-    val ocFileId: Int
+    val ocFileId: Int?
 )

+ 7 - 2
app/src/main/java/com/nextcloud/client/di/AppModule.java

@@ -96,8 +96,13 @@ class AppModule {
 
     @Provides
     @Singleton
-    NextcloudDatabase database(Context context) {
-        return Room.databaseBuilder(context, NextcloudDatabase.class, ProviderMeta.DB_NAME).build();
+    NextcloudDatabase database(Context context, Clock clock) {
+        // TODO move somewhere else to not pollute this file
+        return Room
+            .databaseBuilder(context, NextcloudDatabase.class, ProviderMeta.DB_NAME)
+            .addMigrations(NextcloudDatabase.getLegacyMigrations(context, clock))
+            .addMigrations(NextcloudDatabase.roomMigration)
+            .build();
     }
 
     @Provides

+ 1 - 1
app/src/main/java/com/owncloud/android/MainApp.java

@@ -276,7 +276,7 @@ public class MainApp extends MultiDexApplication implements HasAndroidInjector {
     @SuppressFBWarnings("ST")
     @Override
     public void onCreate() {
-         enableStrictMode();
+        enableStrictMode();
 
         viewThemeUtils = viewThemeUtilsProvider.get();
 

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

@@ -22,8 +22,6 @@
 
 package com.owncloud.android.providers;
 
-import android.accounts.Account;
-import android.accounts.AccountManager;
 import android.content.ContentProvider;
 import android.content.ContentProviderOperation;
 import android.content.ContentProviderResult;
@@ -35,28 +33,18 @@ import android.content.UriMatcher;
 import android.database.Cursor;
 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.Binder;
 import android.text.TextUtils;
 
 import com.nextcloud.client.core.Clock;
 import com.nextcloud.client.database.NextcloudDatabase;
-import com.owncloud.android.MainApp;
 import com.owncloud.android.R;
-import com.owncloud.android.datamodel.OCFile;
-import com.owncloud.android.datamodel.SyncedFolder;
-import com.owncloud.android.db.ProviderMeta;
 import com.owncloud.android.db.ProviderMeta.ProviderTableMeta;
-import com.owncloud.android.files.services.NameCollisionPolicy;
-import com.owncloud.android.lib.common.accounts.AccountUtils;
 import com.owncloud.android.lib.common.utils.Log_OC;
 import com.owncloud.android.lib.resources.shares.ShareType;
-import com.owncloud.android.utils.FileStorageUtils;
 import com.owncloud.android.utils.MimeType;
 
-import java.io.File;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
@@ -96,12 +84,6 @@ public class FileContentProvider extends ContentProvider {
     private static final String TAG = FileContentProvider.class.getSimpleName();
     // todo avoid string concatenation and use string formatting instead later.
     private static final String ERROR = "ERROR ";
-    private static final String SQL = "SQL";
-    private static final String INTEGER = " INTEGER, ";
-    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 UPGRADE_VERSION_MSG = "OUT of the ADD in onUpgrade; oldVersion == %d, newVersion == %d";
     private static final int SINGLE_PATH_SEGMENT = 1;
     public static final int ARBITRARY_DATA_TABLE_INTRODUCTION_VERSION = 20;
     public static final int MINIMUM_PATH_SEGMENTS_SIZE = 1;
@@ -112,9 +94,6 @@ public class FileContentProvider extends ContentProvider {
     private static final String[] PROJECTION_REMOTE_ID = new String[]{
         ProviderTableMeta._ID, ProviderTableMeta.FILE_REMOTE_ID
     };
-    private static final String[] PROJECTION_FILE_AND_STORAGE_PATH = new String[]{
-        ProviderTableMeta._ID, ProviderTableMeta.FILE_STORAGE_PATH, ProviderTableMeta.FILE_PATH
-    };
     private static final String[] PROJECTION_FILE_PATH_AND_OWNER = new String[]{
         ProviderTableMeta._ID, ProviderTableMeta.FILE_PATH, ProviderTableMeta.FILE_ACCOUNT_OWNER
     };
@@ -728,348 +707,6 @@ public class FileContentProvider extends ContentProvider {
         return results;
     }
 
-    private boolean checkIfColumnExists(SQLiteDatabase database, String table, String column) {
-        Cursor cursor = database.rawQuery("SELECT * FROM " + table + " LIMIT 0", null);
-        boolean exists = cursor.getColumnIndex(column) != -1;
-        cursor.close();
-
-        return exists;
-    }
-
-    private void createFilesTable(SQLiteDatabase db) {
-        db.execSQL("CREATE TABLE " + ProviderTableMeta.FILE_TABLE_NAME + "("
-                       + ProviderTableMeta._ID + " INTEGER PRIMARY KEY, "
-                       + ProviderTableMeta.FILE_NAME + TEXT
-                       + ProviderTableMeta.FILE_ENCRYPTED_NAME + TEXT
-                       + ProviderTableMeta.FILE_PATH + TEXT
-                       + ProviderTableMeta.FILE_PATH_DECRYPTED + TEXT
-                       + ProviderTableMeta.FILE_PARENT + INTEGER
-                       + ProviderTableMeta.FILE_CREATION + INTEGER
-                       + ProviderTableMeta.FILE_MODIFIED + INTEGER
-                       + ProviderTableMeta.FILE_CONTENT_TYPE + TEXT
-                       + ProviderTableMeta.FILE_CONTENT_LENGTH + INTEGER
-                       + ProviderTableMeta.FILE_STORAGE_PATH + TEXT
-                       + ProviderTableMeta.FILE_ACCOUNT_OWNER + TEXT
-                       + ProviderTableMeta.FILE_LAST_SYNC_DATE + INTEGER
-                       + ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA + INTEGER
-                       + ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA + INTEGER
-                       + ProviderTableMeta.FILE_ETAG + TEXT
-                       + ProviderTableMeta.FILE_ETAG_ON_SERVER + TEXT
-                       + ProviderTableMeta.FILE_SHARED_VIA_LINK + INTEGER
-                       + ProviderTableMeta.FILE_PERMISSIONS + " TEXT null,"
-                       + ProviderTableMeta.FILE_REMOTE_ID + " TEXT null,"
-                       + ProviderTableMeta.FILE_UPDATE_THUMBNAIL + INTEGER //boolean
-                       + ProviderTableMeta.FILE_IS_DOWNLOADING + INTEGER //boolean
-                       + ProviderTableMeta.FILE_FAVORITE + INTEGER // boolean
-                       + ProviderTableMeta.FILE_IS_ENCRYPTED + INTEGER // boolean
-                       + ProviderTableMeta.FILE_ETAG_IN_CONFLICT + TEXT
-                       + ProviderTableMeta.FILE_SHARED_WITH_SHAREE + INTEGER
-                       + ProviderTableMeta.FILE_MOUNT_TYPE + INTEGER
-                       + ProviderTableMeta.FILE_HAS_PREVIEW + INTEGER
-                       + ProviderTableMeta.FILE_UNREAD_COMMENTS_COUNT + INTEGER
-                       + ProviderTableMeta.FILE_OWNER_ID + TEXT
-                       + ProviderTableMeta.FILE_OWNER_DISPLAY_NAME + TEXT
-                       + ProviderTableMeta.FILE_NOTE + TEXT
-                       + ProviderTableMeta.FILE_SHAREES + TEXT
-                       + ProviderTableMeta.FILE_RICH_WORKSPACE + TEXT
-                       + ProviderTableMeta.FILE_METADATA_SIZE + TEXT
-                       + ProviderTableMeta.FILE_LOCKED + INTEGER // boolean
-                       + ProviderTableMeta.FILE_LOCK_TYPE + INTEGER
-                       + ProviderTableMeta.FILE_LOCK_OWNER + TEXT
-                       + ProviderTableMeta.FILE_LOCK_OWNER_DISPLAY_NAME + TEXT
-                       + ProviderTableMeta.FILE_LOCK_OWNER_EDITOR + TEXT
-                       + ProviderTableMeta.FILE_LOCK_TIMESTAMP + INTEGER
-                       + ProviderTableMeta.FILE_LOCK_TIMEOUT + INTEGER
-                       + ProviderTableMeta.FILE_LOCK_TOKEN + " TEXT );"
-        );
-    }
-
-    private void createOCSharesTable(SQLiteDatabase db) {
-        db.execSQL("CREATE TABLE " + ProviderTableMeta.OCSHARES_TABLE_NAME + "("
-                       + ProviderTableMeta._ID + " INTEGER PRIMARY KEY, "
-                       + ProviderTableMeta.OCSHARES_FILE_SOURCE + INTEGER
-                       + ProviderTableMeta.OCSHARES_ITEM_SOURCE + INTEGER
-                       + ProviderTableMeta.OCSHARES_SHARE_TYPE + INTEGER
-                       + ProviderTableMeta.OCSHARES_SHARE_WITH + TEXT
-                       + ProviderTableMeta.OCSHARES_PATH + TEXT
-                       + ProviderTableMeta.OCSHARES_PERMISSIONS + INTEGER
-                       + ProviderTableMeta.OCSHARES_SHARED_DATE + INTEGER
-                       + ProviderTableMeta.OCSHARES_EXPIRATION_DATE + INTEGER
-                       + ProviderTableMeta.OCSHARES_TOKEN + TEXT
-                       + ProviderTableMeta.OCSHARES_SHARE_WITH_DISPLAY_NAME + TEXT
-                       + ProviderTableMeta.OCSHARES_IS_DIRECTORY + INTEGER  // boolean
-                       + ProviderTableMeta.OCSHARES_USER_ID + INTEGER
-                       + ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED + INTEGER
-                       + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + TEXT
-                       + ProviderTableMeta.OCSHARES_IS_PASSWORD_PROTECTED + INTEGER
-                       + ProviderTableMeta.OCSHARES_NOTE + TEXT
-                       + ProviderTableMeta.OCSHARES_HIDE_DOWNLOAD + INTEGER
-                       + ProviderTableMeta.OCSHARES_SHARE_LINK + TEXT
-                       + ProviderTableMeta.OCSHARES_SHARE_LABEL + " TEXT );");
-    }
-
-    private void createCapabilitiesTable(SQLiteDatabase db) {
-        db.execSQL("CREATE TABLE " + ProviderTableMeta.CAPABILITIES_TABLE_NAME + "("
-                       + ProviderTableMeta._ID + " INTEGER PRIMARY KEY, "
-                       + ProviderTableMeta.CAPABILITIES_ACCOUNT_NAME + TEXT
-                       + ProviderTableMeta.CAPABILITIES_VERSION_MAYOR + INTEGER
-                       + ProviderTableMeta.CAPABILITIES_VERSION_MINOR + INTEGER
-                       + ProviderTableMeta.CAPABILITIES_VERSION_MICRO + INTEGER
-                       + ProviderTableMeta.CAPABILITIES_VERSION_STRING + TEXT
-                       + ProviderTableMeta.CAPABILITIES_VERSION_EDITION + TEXT
-                       + ProviderTableMeta.CAPABILITIES_EXTENDED_SUPPORT + INTEGER
-                       + ProviderTableMeta.CAPABILITIES_CORE_POLLINTERVAL + INTEGER
-                       + ProviderTableMeta.CAPABILITIES_SHARING_API_ENABLED + INTEGER // boolean
-                       + ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_ENABLED + INTEGER  // boolean
-                       + ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_PASSWORD_ENFORCED + INTEGER    // boolean
-                       + ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_EXPIRE_DATE_ENABLED + INTEGER  // boolean
-                       + ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_EXPIRE_DATE_DAYS + INTEGER
-                       + ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_EXPIRE_DATE_ENFORCED + INTEGER // boolean
-                       + ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_SEND_MAIL + INTEGER    // boolean
-                       + ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_UPLOAD + INTEGER       // boolean
-                       + ProviderTableMeta.CAPABILITIES_SHARING_USER_SEND_MAIL + INTEGER      // boolean
-                       + ProviderTableMeta.CAPABILITIES_SHARING_RESHARING + INTEGER           // boolean
-                       + ProviderTableMeta.CAPABILITIES_SHARING_FEDERATION_OUTGOING + INTEGER     // boolean
-                       + ProviderTableMeta.CAPABILITIES_SHARING_FEDERATION_INCOMING + INTEGER     // boolean
-                       + ProviderTableMeta.CAPABILITIES_FILES_BIGFILECHUNKING + INTEGER   // boolean
-                       + ProviderTableMeta.CAPABILITIES_FILES_UNDELETE + INTEGER  // boolean
-                       + ProviderTableMeta.CAPABILITIES_FILES_VERSIONING + INTEGER   // boolean
-                       + ProviderTableMeta.CAPABILITIES_EXTERNAL_LINKS + INTEGER  // boolean
-                       + ProviderTableMeta.CAPABILITIES_SERVER_NAME + TEXT
-                       + ProviderTableMeta.CAPABILITIES_SERVER_COLOR + TEXT
-                       + ProviderTableMeta.CAPABILITIES_SERVER_TEXT_COLOR + TEXT
-                       + ProviderTableMeta.CAPABILITIES_SERVER_ELEMENT_COLOR + TEXT
-                       + ProviderTableMeta.CAPABILITIES_SERVER_SLOGAN + TEXT
-                       + ProviderTableMeta.CAPABILITIES_SERVER_LOGO + TEXT
-                       + ProviderTableMeta.CAPABILITIES_SERVER_BACKGROUND_URL + TEXT
-                       + ProviderTableMeta.CAPABILITIES_END_TO_END_ENCRYPTION + INTEGER
-                       + ProviderTableMeta.CAPABILITIES_ACTIVITY + INTEGER
-                       + ProviderTableMeta.CAPABILITIES_SERVER_BACKGROUND_DEFAULT + INTEGER
-                       + ProviderTableMeta.CAPABILITIES_SERVER_BACKGROUND_PLAIN + INTEGER
-                       + ProviderTableMeta.CAPABILITIES_RICHDOCUMENT + INTEGER
-                       + ProviderTableMeta.CAPABILITIES_RICHDOCUMENT_MIMETYPE_LIST + TEXT
-                       + ProviderTableMeta.CAPABILITIES_RICHDOCUMENT_DIRECT_EDITING + INTEGER
-                       + ProviderTableMeta.CAPABILITIES_RICHDOCUMENT_TEMPLATES + INTEGER
-                       + ProviderTableMeta.CAPABILITIES_RICHDOCUMENT_OPTIONAL_MIMETYPE_LIST + TEXT
-                       + ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_ASK_FOR_OPTIONAL_PASSWORD + INTEGER
-                       + ProviderTableMeta.CAPABILITIES_RICHDOCUMENT_PRODUCT_NAME + TEXT
-                       + ProviderTableMeta.CAPABILITIES_DIRECT_EDITING_ETAG + TEXT
-                       + ProviderTableMeta.CAPABILITIES_USER_STATUS + INTEGER
-                       + ProviderTableMeta.CAPABILITIES_USER_STATUS_SUPPORTS_EMOJI + INTEGER
-                       + ProviderTableMeta.CAPABILITIES_ETAG + TEXT
-                       + ProviderTableMeta.CAPABILITIES_FILES_LOCKING_VERSION + " TEXT );");
-    }
-
-    private void createUploadsTable(SQLiteDatabase db) {
-        db.execSQL("CREATE TABLE " + ProviderTableMeta.UPLOADS_TABLE_NAME + "("
-                       + ProviderTableMeta._ID + " INTEGER PRIMARY KEY, "
-                       + ProviderTableMeta.UPLOADS_LOCAL_PATH + TEXT
-                       + ProviderTableMeta.UPLOADS_REMOTE_PATH + TEXT
-                       + ProviderTableMeta.UPLOADS_ACCOUNT_NAME + TEXT
-                       + ProviderTableMeta.UPLOADS_FILE_SIZE + " LONG, "
-                       + ProviderTableMeta.UPLOADS_STATUS + INTEGER               // UploadStatus
-                       + ProviderTableMeta.UPLOADS_LOCAL_BEHAVIOUR + INTEGER      // Upload LocalBehaviour
-                       + ProviderTableMeta.UPLOADS_UPLOAD_TIME + INTEGER
-                       + ProviderTableMeta.UPLOADS_NAME_COLLISION_POLICY + INTEGER  // boolean
-                       + ProviderTableMeta.UPLOADS_IS_CREATE_REMOTE_FOLDER + INTEGER  // boolean
-                       + ProviderTableMeta.UPLOADS_UPLOAD_END_TIMESTAMP + INTEGER
-                       + ProviderTableMeta.UPLOADS_LAST_RESULT + INTEGER     // Upload LastResult
-                       + ProviderTableMeta.UPLOADS_IS_WHILE_CHARGING_ONLY + INTEGER  // boolean
-                       + ProviderTableMeta.UPLOADS_IS_WIFI_ONLY + INTEGER // boolean
-                       + ProviderTableMeta.UPLOADS_CREATED_BY + INTEGER    // Upload createdBy
-                       + ProviderTableMeta.UPLOADS_FOLDER_UNLOCK_TOKEN + " TEXT );");
-
-        /* before:
-        // PRIMARY KEY should always imply NOT NULL. Unfortunately, due to a
-        // bug in some early versions, this is not the case in SQLite.
-        //db.execSQL("CREATE TABLE " + TABLE_UPLOAD + " (" + " path TEXT PRIMARY KEY NOT NULL UNIQUE,"
-        //        + " uploadStatus INTEGER NOT NULL, uploadObject TEXT NOT NULL);");
-        // uploadStatus is used to easy filtering, it has precedence over
-        // uploadObject.getUploadStatus()
-        */
-    }
-
-    private void createSyncedFoldersTable(SQLiteDatabase db) {
-        db.execSQL("CREATE TABLE " + ProviderTableMeta.SYNCED_FOLDERS_TABLE_NAME + "("
-                       + ProviderTableMeta._ID + " INTEGER PRIMARY KEY, "                 // id
-                       + ProviderTableMeta.SYNCED_FOLDER_LOCAL_PATH + " TEXT, "           // local path
-                       + ProviderTableMeta.SYNCED_FOLDER_REMOTE_PATH + " TEXT, "          // remote path
-                       + ProviderTableMeta.SYNCED_FOLDER_WIFI_ONLY + " INTEGER, "         // wifi_only
-                       + ProviderTableMeta.SYNCED_FOLDER_CHARGING_ONLY + " INTEGER, "     // charging only
-                       + ProviderTableMeta.SYNCED_FOLDER_EXISTING + " INTEGER, "          // existing
-                       + ProviderTableMeta.SYNCED_FOLDER_ENABLED + " INTEGER, "           // enabled
-                       + ProviderTableMeta.SYNCED_FOLDER_ENABLED_TIMESTAMP_MS + " INTEGER, " // enable date
-                       + ProviderTableMeta.SYNCED_FOLDER_SUBFOLDER_BY_DATE + " INTEGER, " // subfolder by date
-                       + ProviderTableMeta.SYNCED_FOLDER_ACCOUNT + "  TEXT, "             // account
-                       + ProviderTableMeta.SYNCED_FOLDER_UPLOAD_ACTION + " INTEGER, "     // upload action
-                       + ProviderTableMeta.SYNCED_FOLDER_NAME_COLLISION_POLICY + " INTEGER, " // name collision policy
-                       + ProviderTableMeta.SYNCED_FOLDER_TYPE + " INTEGER, "              // type
-                       + ProviderTableMeta.SYNCED_FOLDER_HIDDEN + " INTEGER );"           // hidden
-        );
-    }
-
-    private void createExternalLinksTable(SQLiteDatabase db) {
-        db.execSQL("CREATE TABLE " + ProviderTableMeta.EXTERNAL_LINKS_TABLE_NAME + "("
-                       + ProviderTableMeta._ID + " INTEGER PRIMARY KEY, "          // id
-                       + ProviderTableMeta.EXTERNAL_LINKS_ICON_URL + " TEXT, "     // icon url
-                       + ProviderTableMeta.EXTERNAL_LINKS_LANGUAGE + " TEXT, "     // language
-                       + ProviderTableMeta.EXTERNAL_LINKS_TYPE + " INTEGER, "      // type
-                       + ProviderTableMeta.EXTERNAL_LINKS_NAME + " TEXT, "         // name
-                       + ProviderTableMeta.EXTERNAL_LINKS_URL + " TEXT, "          // url
-                       + ProviderTableMeta.EXTERNAL_LINKS_REDIRECT + " INTEGER );" // redirect
-        );
-    }
-
-    private void createArbitraryData(SQLiteDatabase db) {
-        db.execSQL("CREATE TABLE " + ProviderTableMeta.ARBITRARY_DATA_TABLE_NAME + "("
-                       + ProviderTableMeta._ID + " INTEGER PRIMARY KEY, "      // id
-                       + ProviderTableMeta.ARBITRARY_DATA_CLOUD_ID + " TEXT, " // cloud id (account name + FQDN)
-                       + ProviderTableMeta.ARBITRARY_DATA_KEY + " TEXT, "      // key
-                       + ProviderTableMeta.ARBITRARY_DATA_VALUE + " TEXT );"   // value
-        );
-    }
-
-    private void createVirtualTable(SQLiteDatabase db) {
-        db.execSQL("CREATE TABLE " + ProviderTableMeta.VIRTUAL_TABLE_NAME + "("
-                       + ProviderTableMeta._ID + " INTEGER PRIMARY KEY, "          // id
-                       + ProviderTableMeta.VIRTUAL_TYPE + " TEXT, "                // type
-                       + ProviderTableMeta.VIRTUAL_OCFILE_ID + " INTEGER )"        // file id
-                  );
-    }
-
-    private void createFileSystemTable(SQLiteDatabase db) {
-        db.execSQL("CREATE TABLE IF NOT EXISTS " + ProviderTableMeta.FILESYSTEM_TABLE_NAME + "("
-                       + ProviderTableMeta._ID + " INTEGER PRIMARY KEY, "      // id
-                       + ProviderTableMeta.FILESYSTEM_FILE_LOCAL_PATH + " TEXT, "
-                       + ProviderTableMeta.FILESYSTEM_FILE_IS_FOLDER + " INTEGER, "
-                       + ProviderTableMeta.FILESYSTEM_FILE_FOUND_RECENTLY + " LONG, "
-                       + ProviderTableMeta.FILESYSTEM_FILE_SENT_FOR_UPLOAD + " INTEGER, "
-                       + ProviderTableMeta.FILESYSTEM_SYNCED_FOLDER_ID + " STRING, "
-                       + ProviderTableMeta.FILESYSTEM_CRC32 + " STRING, "
-                       + ProviderTableMeta.FILESYSTEM_FILE_MODIFIED + " LONG );"
-        );
-    }
-
-    /**
-     * Version 10 of database does not modify its scheme. It coincides with the upgrade of the
-     * ownCloud account names structure to include in it the path to the server instance. Updating
-     * the account names and path to local files in the files table is a must to keep the existing
-     * account working and the database clean.
-     *
-     * @param db Database where table of files is included.
-     */
-    private void updateAccountName(SQLiteDatabase db) {
-        Log_OC.d(SQL, "THREAD:  " + Thread.currentThread().getName());
-        AccountManager ama = AccountManager.get(getContext());
-        try {
-            // get accounts from AccountManager ;  we can't be sure if accounts in it are updated or not although
-            // we know the update was previously done in {link @FileActivity#onCreate} because the changes through
-            // AccountManager are not synchronous
-            Account[] accounts = AccountManager.get(getContext()).getAccountsByType(MainApp.getAccountType(mContext));
-            String serverUrl;
-            String username;
-            String oldAccountName;
-            String newAccountName;
-            String[] accountOwner = new String[1];
-
-            for (Account account : accounts) {
-                // build both old and new account name
-                serverUrl = ama.getUserData(account, AccountUtils.Constants.KEY_OC_BASE_URL);
-                username = AccountUtils.getUsernameForAccount(account);
-                oldAccountName = AccountUtils.buildAccountNameOld(Uri.parse(serverUrl), username);
-                newAccountName = AccountUtils.buildAccountName(Uri.parse(serverUrl), username);
-
-                // update values in database
-                db.beginTransaction();
-                try {
-                    ContentValues cv = new ContentValues();
-                    cv.put(ProviderTableMeta.FILE_ACCOUNT_OWNER, newAccountName);
-                    accountOwner[0] = oldAccountName;
-                    int num = db.update(ProviderTableMeta.FILE_TABLE_NAME,
-                                        cv,
-                                        ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?",
-                                        accountOwner);
-
-                    Log_OC.d(SQL, "Updated account in database: old name == " + oldAccountName +
-                        ", new name == " + newAccountName + " (" + num + " rows updated )");
-
-                    // update path for downloaded files
-                    updateDownloadedFiles(db, newAccountName, oldAccountName);
-
-                    db.setTransactionSuccessful();
-
-                } catch (SQLException e) {
-                    Log_OC.e(TAG, "SQL Exception upgrading account names or paths in database", e);
-                } finally {
-                    db.endTransaction();
-                }
-            }
-        } catch (Exception e) {
-            Log_OC.e(TAG, "Exception upgrading account names or paths in database", e);
-        }
-    }
-
-    /**
-     * Rename the local ownCloud folder of one account to match the a rename of the account itself.
-     * Updates the table of files in database so that the paths to the local files keep being the
-     * same.
-     *
-     * @param db             Database where table of files is included.
-     * @param newAccountName New name for the target OC account.
-     * @param oldAccountName Old name of the target OC account.
-     */
-    private void updateDownloadedFiles(SQLiteDatabase db, String newAccountName,
-                                       String oldAccountName) {
-
-        String whereClause = ProviderTableMeta.FILE_ACCOUNT_OWNER + "=? AND " +
-            ProviderTableMeta.FILE_STORAGE_PATH + " IS NOT NULL";
-
-        Cursor c = db.query(ProviderTableMeta.FILE_TABLE_NAME,
-                            PROJECTION_FILE_AND_STORAGE_PATH,
-                            whereClause,
-                            new String[]{newAccountName},
-                            null, null, null);
-
-        try {
-            if (c.moveToFirst()) {
-                // create storage path
-                String oldAccountPath = FileStorageUtils.getSavePath(oldAccountName);
-                String newAccountPath = FileStorageUtils.getSavePath(newAccountName);
-
-                // move files
-                File oldAccountFolder = new File(oldAccountPath);
-                File newAccountFolder = new File(newAccountPath);
-                oldAccountFolder.renameTo(newAccountFolder);
-
-                String[] storagePath = new String[1];
-
-                // update database
-                do {
-                    // Update database
-                    String oldPath = c.getString(
-                        c.getColumnIndexOrThrow(ProviderTableMeta.FILE_STORAGE_PATH));
-                    OCFile file = new OCFile(
-                        c.getString(c.getColumnIndexOrThrow(ProviderTableMeta.FILE_PATH)));
-                    String newPath = FileStorageUtils.getDefaultSavePathFor(newAccountName, file);
-
-                    ContentValues cv = new ContentValues();
-                    cv.put(ProviderTableMeta.FILE_STORAGE_PATH, newPath);
-                    storagePath[0] = oldPath;
-                    db.update(ProviderTableMeta.FILE_TABLE_NAME,
-                              cv,
-                              ProviderTableMeta.FILE_STORAGE_PATH + "=?",
-                              storagePath);
-
-                    Log_OC.v(SQL, "Updated path of downloaded file: old file name == " + oldPath +
-                        ", new file name == " + newPath);
-
-                } while (c.moveToNext());
-            }
-        } finally {
-            c.close();
-        }
-    }
-
     private boolean isCallerNotAllowed(Uri uri) {
         switch (mUriMatcher.match(uri)) {
             case SHARES:
@@ -1190,1352 +827,4 @@ public class FileContentProvider extends ContentProvider {
             throw new IllegalArgumentException("Invalid token " + token);
         }
     }
-
-    class DataBaseHelper extends SQLiteOpenHelper {
-        DataBaseHelper(Context context) {
-            super(context, ProviderMeta.DB_NAME, null, ProviderMeta.DB_VERSION);
-        }
-
-        @Override
-        public void onCreate(SQLiteDatabase db) {
-            // files table
-            Log_OC.i(SQL, "Entering in onCreate");
-            createFilesTable(db);
-
-            // Create OCShares table
-            createOCSharesTable(db);
-
-            // Create capabilities table
-            createCapabilitiesTable(db);
-
-            // Create uploads table
-            createUploadsTable(db);
-
-            // Create synced folders table
-            createSyncedFoldersTable(db);
-
-            // Create external links table
-            createExternalLinksTable(db);
-
-            // Create arbitrary data table
-            createArbitraryData(db);
-
-            // Create virtual table
-            createVirtualTable(db);
-
-            // Create filesystem table
-            createFileSystemTable(db);
-        }
-
-        @Override
-        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
-            Log_OC.i(SQL, "Entering in onUpgrade");
-            boolean upgraded = false;
-            if (oldVersion == 1 && newVersion >= 2) {
-                Log_OC.i(SQL, "Entering in the #2 ADD in onUpgrade");
-                db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
-                               ADD_COLUMN + ProviderTableMeta.FILE_KEEP_IN_SYNC + " INTEGER " +
-                               " DEFAULT 0");
-                upgraded = true;
-            }
-            if (oldVersion < 3 && newVersion >= 3) {
-                Log_OC.i(SQL, "Entering in the #3 ADD in onUpgrade");
-                db.beginTransaction();
-                try {
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
-                                   ADD_COLUMN + ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA +
-                                   " INTEGER " + " DEFAULT 0");
-
-                    // assume there are not local changes pending to upload
-                    db.execSQL("UPDATE " + ProviderTableMeta.FILE_TABLE_NAME +
-                                   " SET " + ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA + " = "
-                                   + System.currentTimeMillis() +
-                                   " WHERE " + ProviderTableMeta.FILE_STORAGE_PATH + " IS NOT NULL");
-
-                    upgraded = true;
-                    db.setTransactionSuccessful();
-                } finally {
-                    db.endTransaction();
-                }
-            }
-            if (oldVersion < 4 && newVersion >= 4) {
-                Log_OC.i(SQL, "Entering in the #4 ADD in onUpgrade");
-                db.beginTransaction();
-                try {
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
-                                   ADD_COLUMN + ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA +
-                                   " INTEGER " + " DEFAULT 0");
-
-                    db.execSQL("UPDATE " + ProviderTableMeta.FILE_TABLE_NAME +
-                                   " SET " + ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA + " = " +
-                                   ProviderTableMeta.FILE_MODIFIED +
-                                   " WHERE " + ProviderTableMeta.FILE_STORAGE_PATH + " IS NOT NULL");
-
-                    upgraded = true;
-                    db.setTransactionSuccessful();
-                } finally {
-                    db.endTransaction();
-                }
-            }
-
-            if (!upgraded) {
-                Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
-            }
-
-            if (oldVersion < 5 && newVersion >= 5) {
-                Log_OC.i(SQL, "Entering in the #5 ADD in onUpgrade");
-                db.beginTransaction();
-                try {
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
-                                   ADD_COLUMN + ProviderTableMeta.FILE_ETAG + " TEXT " +
-                                   " DEFAULT NULL");
-
-                    upgraded = true;
-                    db.setTransactionSuccessful();
-                } finally {
-                    db.endTransaction();
-                }
-            }
-            if (!upgraded) {
-                Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
-            }
-
-            if (oldVersion < 6 && newVersion >= 6) {
-                Log_OC.i(SQL, "Entering in the #6 ADD in onUpgrade");
-                db.beginTransaction();
-                try {
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
-                                   ADD_COLUMN + ProviderTableMeta.FILE_SHARED_VIA_LINK + " INTEGER " +
-                                   " DEFAULT 0");
-
-                    // Create table OCShares
-                    createOCSharesTable(db);
-
-                    upgraded = true;
-                    db.setTransactionSuccessful();
-                } finally {
-                    db.endTransaction();
-                }
-            }
-            if (!upgraded) {
-                Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
-            }
-
-            if (oldVersion < 7 && newVersion >= 7) {
-                Log_OC.i(SQL, "Entering in the #7 ADD in onUpgrade");
-                db.beginTransaction();
-                try {
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
-                                   ADD_COLUMN + ProviderTableMeta.FILE_PERMISSIONS + " TEXT " +
-                                   " DEFAULT NULL");
-
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
-                                   ADD_COLUMN + ProviderTableMeta.FILE_REMOTE_ID + " TEXT " +
-                                   " DEFAULT NULL");
-
-                    upgraded = true;
-                    db.setTransactionSuccessful();
-                } finally {
-                    db.endTransaction();
-                }
-            }
-            if (!upgraded) {
-                Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
-            }
-
-            if (oldVersion < 8 && newVersion >= 8) {
-                Log_OC.i(SQL, "Entering in the #8 ADD in onUpgrade");
-                db.beginTransaction();
-                try {
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
-                                   ADD_COLUMN + ProviderTableMeta.FILE_UPDATE_THUMBNAIL + " INTEGER " +
-                                   " DEFAULT 0");
-
-                    upgraded = true;
-                    db.setTransactionSuccessful();
-                } finally {
-                    db.endTransaction();
-                }
-            }
-            if (!upgraded) {
-                Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
-            }
-
-            if (oldVersion < 9 && newVersion >= 9) {
-                Log_OC.i(SQL, "Entering in the #9 ADD in onUpgrade");
-                db.beginTransaction();
-                try {
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
-                                   ADD_COLUMN + ProviderTableMeta.FILE_IS_DOWNLOADING + " INTEGER " +
-                                   " DEFAULT 0");
-
-                    upgraded = true;
-                    db.setTransactionSuccessful();
-                } finally {
-                    db.endTransaction();
-                }
-            }
-            if (!upgraded) {
-                Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
-            }
-
-            if (oldVersion < 10 && newVersion >= 10) {
-                Log_OC.i(SQL, "Entering in the #10 ADD in onUpgrade");
-                updateAccountName(db);
-                upgraded = true;
-            }
-            if (!upgraded) {
-                Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
-            }
-
-            if (oldVersion < 11 && newVersion >= 11) {
-                Log_OC.i(SQL, "Entering in the #11 ADD in onUpgrade");
-                db.beginTransaction();
-                try {
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
-                                   ADD_COLUMN + ProviderTableMeta.FILE_ETAG_IN_CONFLICT + " TEXT " +
-                                   " DEFAULT NULL");
-
-                    upgraded = true;
-                    db.setTransactionSuccessful();
-                } finally {
-                    db.endTransaction();
-                }
-            }
-
-            if (!upgraded) {
-                Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
-            }
-
-            if (oldVersion < 12 && newVersion >= 12) {
-                Log_OC.i(SQL, "Entering in the #12 ADD in onUpgrade");
-                db.beginTransaction();
-                try {
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
-                                   ADD_COLUMN + ProviderTableMeta.FILE_SHARED_WITH_SHAREE + " INTEGER " +
-                                   " DEFAULT 0");
-                    upgraded = true;
-                    db.setTransactionSuccessful();
-                } finally {
-                    db.endTransaction();
-                }
-            }
-            if (!upgraded) {
-                Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
-            }
-
-            if (oldVersion < 13 && newVersion >= 13) {
-                Log_OC.i(SQL, "Entering in the #13 ADD in onUpgrade");
-                db.beginTransaction();
-                try {
-                    // Create capabilities table
-                    createCapabilitiesTable(db);
-                    upgraded = true;
-                    db.setTransactionSuccessful();
-                } finally {
-                    db.endTransaction();
-                }
-            }
-
-            if (oldVersion < 14 && newVersion >= 14) {
-                Log_OC.i(SQL, "Entering in the #14 ADD in onUpgrade");
-                db.beginTransaction();
-                try {
-                    // drop old instant_upload table
-                    db.execSQL("DROP TABLE IF EXISTS " + "instant_upload" + ";");
-                    // Create uploads table
-                    createUploadsTable(db);
-                    upgraded = true;
-                    db.setTransactionSuccessful();
-                } finally {
-                    db.endTransaction();
-                }
-            }
-
-            if (oldVersion < 15 && newVersion >= 15) {
-                Log_OC.i(SQL, "Entering in the #15 ADD in onUpgrade");
-                db.beginTransaction();
-                try {
-                    // drop old capabilities table
-                    db.execSQL("DROP TABLE IF EXISTS " + "capabilities" + ";");
-                    // Create uploads table
-                    createCapabilitiesTable(db);
-                    upgraded = true;
-                    db.setTransactionSuccessful();
-                } finally {
-                    db.endTransaction();
-                }
-            }
-
-            if (oldVersion < 16 && newVersion >= 16) {
-                Log_OC.i(SQL, "Entering in the #16 ADD synced folders table");
-                db.beginTransaction();
-                try {
-                    // Create synced folders table
-                    createSyncedFoldersTable(db);
-                    upgraded = true;
-                    db.setTransactionSuccessful();
-                } finally {
-                    db.endTransaction();
-                }
-            }
-
-            if (!upgraded) {
-                Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
-            }
-
-            if (oldVersion < 17 && newVersion >= 17) {
-                Log_OC.i(SQL, "Entering in the #17 ADD in onUpgrade");
-                db.beginTransaction();
-                try {
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
-                                   ADD_COLUMN + ProviderTableMeta.FILE_FAVORITE +
-                                   " INTEGER " + " DEFAULT 0");
-
-                    upgraded = true;
-                    db.setTransactionSuccessful();
-                } finally {
-                    db.endTransaction();
-                }
-            }
-
-            if (!upgraded) {
-                Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
-            }
-
-            if (oldVersion < 18 && newVersion >= 18) {
-                Log_OC.i(SQL, "Entering in the #18 Adding external link column to capabilities");
-                db.beginTransaction();
-                try {
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
-                                   ADD_COLUMN + ProviderTableMeta.CAPABILITIES_EXTERNAL_LINKS +
-                                   " INTEGER " + " DEFAULT -1");
-
-                    upgraded = true;
-                    db.setTransactionSuccessful();
-                } finally {
-                    db.endTransaction();
-                }
-            }
-
-            if (!upgraded) {
-                Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
-            }
-
-            if (oldVersion < 19 && newVersion >= 19) {
-                Log_OC.i(SQL, "Entering in the #19 Adding external link column to capabilities");
-                db.beginTransaction();
-                try {
-                    createExternalLinksTable(db);
-                    upgraded = true;
-                    db.setTransactionSuccessful();
-                } finally {
-                    db.endTransaction();
-                }
-            }
-
-            if (!upgraded) {
-                Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
-            }
-
-            if (oldVersion < 20 && newVersion >= 20) {
-                Log_OC.i(SQL, "Entering in the #20 Adding arbitrary data table");
-                db.beginTransaction();
-                try {
-                    createArbitraryData(db);
-                    upgraded = true;
-                    db.setTransactionSuccessful();
-                } finally {
-                    db.endTransaction();
-                }
-            }
-
-            if (!upgraded) {
-                Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
-            }
-
-            if (oldVersion < 21 && newVersion >= 21) {
-                Log_OC.i(SQL, "Entering in the #21 Adding virtual table");
-                db.beginTransaction();
-                try {
-                    createVirtualTable(db);
-                    upgraded = true;
-                    db.setTransactionSuccessful();
-                } finally {
-                    db.endTransaction();
-                }
-            }
-
-            if (!upgraded) {
-                Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
-            }
-
-            if (oldVersion < 22 && newVersion >= 22) {
-                Log_OC.i(SQL, "Entering in the #22 Adding user theming to capabilities table");
-                db.beginTransaction();
-                try {
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
-                                   ADD_COLUMN + ProviderTableMeta.CAPABILITIES_SERVER_NAME + " TEXT ");
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
-                                   ADD_COLUMN + ProviderTableMeta.CAPABILITIES_SERVER_COLOR + " TEXT ");
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
-                                   ADD_COLUMN + ProviderTableMeta.CAPABILITIES_SERVER_BACKGROUND_URL + " TEXT ");
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
-                                   ADD_COLUMN + ProviderTableMeta.CAPABILITIES_SERVER_SLOGAN + " TEXT ");
-                    upgraded = true;
-                    db.setTransactionSuccessful();
-                } finally {
-                    db.endTransaction();
-                }
-            }
-
-            if (!upgraded) {
-                Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
-            }
-
-            if (oldVersion < 23 && newVersion >= 23) {
-                Log_OC.i(SQL, "Entering in the #23 adding type column for synced folders, Create filesystem table");
-                db.beginTransaction();
-                try {
-                    // add type column default being CUSTOM (0)
-                    if (!checkIfColumnExists(db, ProviderTableMeta.SYNCED_FOLDERS_TABLE_NAME,
-                                             ProviderTableMeta.SYNCED_FOLDER_TYPE)) {
-                        Log_OC.i(SQL, "Add type column and default value 0 (CUSTOM) to synced_folders table");
-                        db.execSQL(ALTER_TABLE + ProviderTableMeta.SYNCED_FOLDERS_TABLE_NAME +
-                                       ADD_COLUMN + ProviderTableMeta.SYNCED_FOLDER_TYPE +
-                                       " INTEGER " + " DEFAULT 0");
-                    } else {
-                        Log_OC.i(SQL, "Type column of synced_folders table already exists");
-                    }
-
-                    if (!checkIfColumnExists(db, ProviderTableMeta.UPLOADS_TABLE_NAME,
-                                             ProviderTableMeta.UPLOADS_IS_WIFI_ONLY)) {
-                        Log_OC.i(SQL, "Add charging and wifi columns to uploads");
-                        db.execSQL(ALTER_TABLE + ProviderTableMeta.UPLOADS_TABLE_NAME +
-                                       ADD_COLUMN + ProviderTableMeta.UPLOADS_IS_WIFI_ONLY +
-                                       " INTEGER " + " DEFAULT 0");
-                    } else {
-                        Log_OC.i(SQL, "Wifi column of uploads table already exists");
-                    }
-
-                    if (!checkIfColumnExists(db, ProviderTableMeta.UPLOADS_TABLE_NAME,
-                                             ProviderTableMeta.UPLOADS_IS_WHILE_CHARGING_ONLY)) {
-                        db.execSQL(ALTER_TABLE + ProviderTableMeta.UPLOADS_TABLE_NAME +
-                                       ADD_COLUMN + ProviderTableMeta.UPLOADS_IS_WHILE_CHARGING_ONLY +
-                                       " INTEGER " + " DEFAULT 0");
-                    } else {
-                        Log_OC.i(SQL, "Charging column of uploads table already exists");
-                    }
-
-                    // create Filesystem table
-                    Log_OC.i(SQL, "Create filesystem table");
-                    createFileSystemTable(db);
-
-                    upgraded = true;
-                    db.setTransactionSuccessful();
-
-                } catch (Throwable t) {
-                    Log_OC.e(TAG, "ERROR!", t);
-                } finally {
-                    db.endTransaction();
-                }
-            }
-
-            if (!upgraded) {
-                Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
-            }
-
-            if (oldVersion < 24 && newVersion >= 24) {
-                Log_OC.i(SQL, "Entering in the #24 Re-adding user theming to capabilities table");
-                db.beginTransaction();
-                try {
-                    if (!checkIfColumnExists(db, ProviderTableMeta.CAPABILITIES_TABLE_NAME,
-                                             ProviderTableMeta.CAPABILITIES_SERVER_NAME)) {
-                        db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
-                                       ADD_COLUMN + ProviderTableMeta.CAPABILITIES_SERVER_NAME + " TEXT ");
-                    }
-
-                    if (!checkIfColumnExists(db, ProviderTableMeta.CAPABILITIES_TABLE_NAME,
-                                             ProviderTableMeta.CAPABILITIES_SERVER_COLOR)) {
-                        db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
-                                       ADD_COLUMN + ProviderTableMeta.CAPABILITIES_SERVER_COLOR + " TEXT ");
-                    }
-
-                    if (!checkIfColumnExists(db, ProviderTableMeta.CAPABILITIES_TABLE_NAME,
-                                             ProviderTableMeta.CAPABILITIES_SERVER_BACKGROUND_URL)) {
-                        db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
-                                       ADD_COLUMN + ProviderTableMeta.CAPABILITIES_SERVER_BACKGROUND_URL + " TEXT ");
-                    }
-
-                    if (!checkIfColumnExists(db, ProviderTableMeta.CAPABILITIES_TABLE_NAME,
-                                             ProviderTableMeta.CAPABILITIES_SERVER_SLOGAN)) {
-                        db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
-                                       ADD_COLUMN + ProviderTableMeta.CAPABILITIES_SERVER_SLOGAN + " TEXT ");
-                    }
-
-                    upgraded = true;
-                    db.setTransactionSuccessful();
-                } finally {
-                    db.endTransaction();
-                }
-            }
-
-            if (!upgraded) {
-                Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
-            }
-
-            if (oldVersion < 25 && newVersion >= 25) {
-                Log_OC.i(SQL, "Entering in the #25 Adding encryption flag to file");
-                db.beginTransaction();
-                try {
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
-                                   ADD_COLUMN + ProviderTableMeta.FILE_IS_ENCRYPTED + " INTEGER ");
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
-                                   ADD_COLUMN + ProviderTableMeta.FILE_ENCRYPTED_NAME + " TEXT ");
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
-                                   ADD_COLUMN + ProviderTableMeta.CAPABILITIES_END_TO_END_ENCRYPTION + " INTEGER ");
-                    upgraded = true;
-                    db.setTransactionSuccessful();
-                } finally {
-                    db.endTransaction();
-                }
-            }
-
-            if (!upgraded) {
-                Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
-            }
-
-            if (oldVersion < 26 && newVersion >= 26) {
-                Log_OC.i(SQL, "Entering in the #26 Adding text and element color to capabilities");
-                db.beginTransaction();
-                try {
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
-                                   ADD_COLUMN + ProviderTableMeta.CAPABILITIES_SERVER_TEXT_COLOR + " TEXT ");
-
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
-                                   ADD_COLUMN + ProviderTableMeta.CAPABILITIES_SERVER_ELEMENT_COLOR + " TEXT ");
-
-                    upgraded = true;
-                    db.setTransactionSuccessful();
-                } finally {
-                    db.endTransaction();
-                }
-            }
-
-            if (!upgraded) {
-                Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
-            }
-
-            if (!upgraded) {
-                Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
-            }
-
-            if (oldVersion < 27 && newVersion >= 27) {
-                Log_OC.i(SQL, "Entering in the #27 Adding token to ocUpload");
-                db.beginTransaction();
-                try {
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.UPLOADS_TABLE_NAME +
-                                   ADD_COLUMN + ProviderTableMeta.UPLOADS_FOLDER_UNLOCK_TOKEN + " TEXT ");
-                    upgraded = true;
-                    db.setTransactionSuccessful();
-                } finally {
-                    db.endTransaction();
-                }
-            }
-
-            if (!upgraded) {
-                Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
-            }
-
-            if (oldVersion < 28 && newVersion >= 28) {
-                Log_OC.i(SQL, "Entering in the #28 Adding CRC32 column to filesystem table");
-                db.beginTransaction();
-                try {
-                    if (!checkIfColumnExists(db, ProviderTableMeta.FILESYSTEM_TABLE_NAME,
-                                             ProviderTableMeta.FILESYSTEM_CRC32)) {
-                        db.execSQL(ALTER_TABLE + ProviderTableMeta.FILESYSTEM_TABLE_NAME +
-                                       ADD_COLUMN + ProviderTableMeta.FILESYSTEM_CRC32 + " TEXT ");
-                    }
-                    upgraded = true;
-                    db.setTransactionSuccessful();
-                } finally {
-                    db.endTransaction();
-                }
-            }
-
-            if (!upgraded) {
-                Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
-            }
-
-            if (oldVersion < 29 && newVersion >= 29) {
-                Log_OC.i(SQL, "Entering in the #29 Adding background default/plain to capabilities");
-                db.beginTransaction();
-                try {
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
-                                   ADD_COLUMN + ProviderTableMeta.CAPABILITIES_SERVER_BACKGROUND_DEFAULT + " INTEGER ");
-
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
-                                   ADD_COLUMN + ProviderTableMeta.CAPABILITIES_SERVER_BACKGROUND_PLAIN + " INTEGER ");
-
-                    upgraded = true;
-                    db.setTransactionSuccessful();
-                } finally {
-                    db.endTransaction();
-                }
-            }
-
-            if (!upgraded) {
-                Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
-            }
-
-            if (oldVersion < 30 && newVersion >= 30) {
-                Log_OC.i(SQL, "Entering in the #30 Re-add 25, 26 if needed");
-                db.beginTransaction();
-                try {
-                    if (!checkIfColumnExists(db, ProviderTableMeta.FILE_TABLE_NAME,
-                                             ProviderTableMeta.FILE_IS_ENCRYPTED)) {
-                        db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
-                                       ADD_COLUMN + ProviderTableMeta.FILE_IS_ENCRYPTED + " INTEGER ");
-                    }
-                    if (!checkIfColumnExists(db, ProviderTableMeta.FILE_TABLE_NAME,
-                                             ProviderTableMeta.FILE_ENCRYPTED_NAME)) {
-                        db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
-                                       ADD_COLUMN + ProviderTableMeta.FILE_ENCRYPTED_NAME + " TEXT ");
-                    }
-                    if (oldVersion > ARBITRARY_DATA_TABLE_INTRODUCTION_VERSION) {
-                        if (!checkIfColumnExists(db, ProviderTableMeta.CAPABILITIES_TABLE_NAME,
-                                                 ProviderTableMeta.CAPABILITIES_END_TO_END_ENCRYPTION)) {
-                            db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
-                                           ADD_COLUMN + ProviderTableMeta.CAPABILITIES_END_TO_END_ENCRYPTION + " INTEGER ");
-                        }
-                        if (!checkIfColumnExists(db, ProviderTableMeta.CAPABILITIES_TABLE_NAME,
-                                                 ProviderTableMeta.CAPABILITIES_SERVER_TEXT_COLOR)) {
-                            db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
-                                           ADD_COLUMN + ProviderTableMeta.CAPABILITIES_SERVER_TEXT_COLOR + " TEXT ");
-                        }
-                        if (!checkIfColumnExists(db, ProviderTableMeta.CAPABILITIES_TABLE_NAME,
-                                                 ProviderTableMeta.CAPABILITIES_SERVER_ELEMENT_COLOR)) {
-                            db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
-                                           ADD_COLUMN + ProviderTableMeta.CAPABILITIES_SERVER_ELEMENT_COLOR + " TEXT ");
-                        }
-                        if (!checkIfColumnExists(db, ProviderTableMeta.FILESYSTEM_TABLE_NAME,
-                                                 ProviderTableMeta.FILESYSTEM_CRC32)) {
-                            try {
-                                db.execSQL(ALTER_TABLE + ProviderTableMeta.FILESYSTEM_TABLE_NAME +
-                                               ADD_COLUMN + ProviderTableMeta.FILESYSTEM_CRC32 + " TEXT ");
-                            } catch (SQLiteException e) {
-                                Log_OC.d(TAG, "Known problem on adding same column twice when upgrading from 24->30");
-                            }
-                        }
-                    }
-
-                    upgraded = true;
-                    db.setTransactionSuccessful();
-                } finally {
-                    db.endTransaction();
-                }
-            }
-
-            if (!upgraded) {
-                Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
-            }
-
-            if (oldVersion < 31 && newVersion >= 31) {
-                Log_OC.i(SQL, "Entering in the #31 add mount type");
-                db.beginTransaction();
-                try {
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
-                                   ADD_COLUMN + ProviderTableMeta.FILE_MOUNT_TYPE + " INTEGER ");
-
-                    upgraded = true;
-                    db.setTransactionSuccessful();
-                } finally {
-                    db.endTransaction();
-                }
-            }
-
-            if (!upgraded) {
-                Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
-            }
-
-            if (oldVersion < 32 && newVersion >= 32) {
-                Log_OC.i(SQL, "Entering in the #32 add ocshares.is_password_protected");
-                db.beginTransaction();
-                try {
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.OCSHARES_TABLE_NAME +
-                                   ADD_COLUMN + ProviderTableMeta.OCSHARES_IS_PASSWORD_PROTECTED + " INTEGER "); // boolean
-
-                    upgraded = true;
-                    db.setTransactionSuccessful();
-                } finally {
-                    db.endTransaction();
-                }
-            }
-
-            if (!upgraded) {
-                Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
-            }
-
-            if (oldVersion < 33 && newVersion >= 33) {
-                Log_OC.i(SQL, "Entering in the #3 Adding activity to capability");
-                db.beginTransaction();
-                try {
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
-                                   ADD_COLUMN + ProviderTableMeta.CAPABILITIES_ACTIVITY + " INTEGER ");
-                    upgraded = true;
-                    db.setTransactionSuccessful();
-                } finally {
-                    db.endTransaction();
-                }
-            }
-
-            if (!upgraded) {
-                Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
-            }
-
-            if (oldVersion < 34 && newVersion >= 34) {
-                Log_OC.i(SQL, "Entering in the #34 add redirect to external links");
-                db.beginTransaction();
-                try {
-                    if (!checkIfColumnExists(db, ProviderTableMeta.EXTERNAL_LINKS_TABLE_NAME,
-                                             ProviderTableMeta.EXTERNAL_LINKS_REDIRECT)) {
-                        db.execSQL(ALTER_TABLE + ProviderTableMeta.EXTERNAL_LINKS_TABLE_NAME +
-                                       ADD_COLUMN + ProviderTableMeta.EXTERNAL_LINKS_REDIRECT + " INTEGER "); // boolean
-                    }
-                    upgraded = true;
-                    db.setTransactionSuccessful();
-                } finally {
-                    db.endTransaction();
-                }
-            }
-
-            if (!upgraded) {
-                Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
-            }
-
-            if (oldVersion < 35 && newVersion >= 35) {
-                Log_OC.i(SQL, "Entering in the #35 add note to share table");
-                db.beginTransaction();
-                try {
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.OCSHARES_TABLE_NAME +
-                                   ADD_COLUMN + ProviderTableMeta.OCSHARES_NOTE + " TEXT ");
-
-                    upgraded = true;
-                    db.setTransactionSuccessful();
-                } finally {
-                    db.endTransaction();
-                }
-            }
-
-            if (!upgraded) {
-                Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
-            }
-
-            if (oldVersion < 36 && newVersion >= 36) {
-                Log_OC.i(SQL, "Entering in the #36 add has-preview to file table");
-                db.beginTransaction();
-                try {
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
-                                   ADD_COLUMN + ProviderTableMeta.FILE_HAS_PREVIEW + " INTEGER ");
-
-                    upgraded = true;
-                    db.setTransactionSuccessful();
-                } finally {
-                    db.endTransaction();
-                }
-            }
-
-            if (!upgraded) {
-                Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
-            }
-
-            if (oldVersion < 37 && newVersion >= 37) {
-                Log_OC.i(SQL, "Entering in the #37 add hide-download to share table");
-                db.beginTransaction();
-                try {
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.OCSHARES_TABLE_NAME +
-                                   ADD_COLUMN + ProviderTableMeta.OCSHARES_HIDE_DOWNLOAD + " INTEGER ");
-
-                    upgraded = true;
-                    db.setTransactionSuccessful();
-                } finally {
-                    db.endTransaction();
-                }
-            }
-
-            if (!upgraded) {
-                Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
-            }
-
-            if (oldVersion < 38 && newVersion >= 38) {
-                Log_OC.i(SQL, "Entering in the #38 add richdocuments");
-                db.beginTransaction();
-                try {
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
-                                   ADD_COLUMN + ProviderTableMeta.CAPABILITIES_RICHDOCUMENT + " INTEGER "); // boolean
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
-                                   ADD_COLUMN + ProviderTableMeta.CAPABILITIES_RICHDOCUMENT_MIMETYPE_LIST + " TEXT "); // string
-
-                    upgraded = true;
-                    db.setTransactionSuccessful();
-                } finally {
-                    db.endTransaction();
-                }
-            }
-
-            if (!upgraded) {
-                Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
-            }
-
-            if (oldVersion < 39 && newVersion >= 39) {
-                Log_OC.i(SQL, "Entering in the #39 add richdocuments direct editing");
-                db.beginTransaction();
-                try {
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
-                                   ADD_COLUMN + ProviderTableMeta.CAPABILITIES_RICHDOCUMENT_DIRECT_EDITING + " INTEGER "); // bool
-
-                    upgraded = true;
-                    db.setTransactionSuccessful();
-                } finally {
-                    db.endTransaction();
-                }
-            }
-
-            if (!upgraded) {
-                Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
-            }
-
-            if (oldVersion < 40 && newVersion >= 40) {
-                Log_OC.i(SQL, "Entering in the #40 add unreadCommentsCount to file table");
-                db.beginTransaction();
-                try {
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
-                                   ADD_COLUMN + ProviderTableMeta.FILE_UNREAD_COMMENTS_COUNT + " INTEGER ");
-
-                    upgraded = true;
-                    db.setTransactionSuccessful();
-                } finally {
-                    db.endTransaction();
-                }
-            }
-
-            if (!upgraded) {
-                Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
-            }
-
-            if (oldVersion < 41 && newVersion >= 41) {
-                Log_OC.i(SQL, "Entering in the #41 add eTagOnServer");
-                db.beginTransaction();
-                try {
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
-                                   ADD_COLUMN + ProviderTableMeta.FILE_ETAG_ON_SERVER + " TEXT ");
-
-                    upgraded = true;
-                    db.setTransactionSuccessful();
-                } finally {
-                    db.endTransaction();
-                }
-            }
-
-            if (!upgraded) {
-                Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
-            }
-
-            if (oldVersion < 42 && newVersion >= 42) {
-                Log_OC.i(SQL, "Entering in the #42 add richDocuments templates");
-                db.beginTransaction();
-                try {
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
-                                   ADD_COLUMN + ProviderTableMeta.CAPABILITIES_RICHDOCUMENT_TEMPLATES + " INTEGER ");
-
-                    upgraded = true;
-                    db.setTransactionSuccessful();
-                } finally {
-                    db.endTransaction();
-                }
-            }
-
-            if (!upgraded) {
-                Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
-            }
-
-            if (oldVersion < 43 && newVersion >= 43) {
-                Log_OC.i(SQL, "Entering in the #43 add ownerId and owner display name to file table");
-                db.beginTransaction();
-                try {
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
-                                   ADD_COLUMN + ProviderTableMeta.FILE_OWNER_ID + " TEXT ");
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
-                                   ADD_COLUMN + ProviderTableMeta.FILE_OWNER_DISPLAY_NAME + " TEXT ");
-
-                    upgraded = true;
-                    db.setTransactionSuccessful();
-                } finally {
-                    db.endTransaction();
-                }
-            }
-
-            if (!upgraded) {
-                Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
-            }
-
-            if (oldVersion < 44 && newVersion >= 44) {
-                Log_OC.i(SQL, "Entering in the #44 add note to file table");
-                db.beginTransaction();
-                try {
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
-                                   ADD_COLUMN + ProviderTableMeta.FILE_NOTE + " TEXT ");
-
-                    upgraded = true;
-                    db.setTransactionSuccessful();
-                } finally {
-                    db.endTransaction();
-                }
-            }
-
-            if (!upgraded) {
-                Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
-            }
-
-            if (oldVersion < 45 && newVersion >= 45) {
-                Log_OC.i(SQL, "Entering in the #45 add sharees to file table");
-                db.beginTransaction();
-                try {
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
-                                   ADD_COLUMN + ProviderTableMeta.FILE_SHAREES + " TEXT ");
-
-                    upgraded = true;
-                    db.setTransactionSuccessful();
-                } finally {
-                    db.endTransaction();
-                }
-            }
-
-            if (!upgraded) {
-                Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
-            }
-
-            if (oldVersion < 46 && newVersion >= 46) {
-                Log_OC.i(SQL, "Entering in the #46 add optional mimetypes to capabilities table");
-                db.beginTransaction();
-                try {
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
-                                   ADD_COLUMN + ProviderTableMeta.CAPABILITIES_RICHDOCUMENT_OPTIONAL_MIMETYPE_LIST
-                                   + " TEXT ");
-
-                    upgraded = true;
-                    db.setTransactionSuccessful();
-                } finally {
-                    db.endTransaction();
-                }
-            }
-
-            if (!upgraded) {
-                Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
-            }
-
-            if (oldVersion < 47 && newVersion >= 47) {
-                Log_OC.i(SQL, "Entering in the #47 add askForPassword to capability table");
-                db.beginTransaction();
-                try {
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
-                                   ADD_COLUMN + ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_ASK_FOR_OPTIONAL_PASSWORD +
-                                   " INTEGER ");
-
-                    upgraded = true;
-                    db.setTransactionSuccessful();
-                } finally {
-                    db.endTransaction();
-                }
-            }
-
-            if (!upgraded) {
-                Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
-            }
-
-            if (oldVersion < 48 && newVersion >= 48) {
-                Log_OC.i(SQL, "Entering in the #48 add product name to capabilities table");
-                db.beginTransaction();
-                try {
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
-                                   ADD_COLUMN + ProviderTableMeta.CAPABILITIES_RICHDOCUMENT_PRODUCT_NAME + " TEXT ");
-
-                    upgraded = true;
-                    db.setTransactionSuccessful();
-                } finally {
-                    db.endTransaction();
-                }
-            }
-
-            if (!upgraded) {
-                Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
-            }
-
-            if (oldVersion < 49 && newVersion >= 49) {
-                Log_OC.i(SQL, "Entering in the #49 add extended support to capabilities table");
-                db.beginTransaction();
-                try {
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
-                                   ADD_COLUMN + ProviderTableMeta.CAPABILITIES_EXTENDED_SUPPORT + " INTEGER ");
-
-                    upgraded = true;
-                    db.setTransactionSuccessful();
-                } finally {
-                    db.endTransaction();
-                }
-            }
-
-            if (!upgraded) {
-                Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
-            }
-
-            if (oldVersion < 50 && newVersion >= 50) {
-                Log_OC.i(SQL, "Entering in the #50 add persistent enable date to synced_folders table");
-                db.beginTransaction();
-                try {
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.SYNCED_FOLDERS_TABLE_NAME +
-                                   ADD_COLUMN + ProviderTableMeta.SYNCED_FOLDER_ENABLED_TIMESTAMP_MS + " INTEGER ");
-
-                    db.execSQL("UPDATE " + ProviderTableMeta.SYNCED_FOLDERS_TABLE_NAME + " SET " +
-                                   ProviderTableMeta.SYNCED_FOLDER_ENABLED_TIMESTAMP_MS + " = CASE " +
-                                   " WHEN enabled = 0 THEN " + SyncedFolder.EMPTY_ENABLED_TIMESTAMP_MS + " " +
-                                   " ELSE " + clock.getCurrentTime() +
-                                   " END ");
-
-                    upgraded = true;
-                    db.setTransactionSuccessful();
-                } finally {
-                    db.endTransaction();
-                }
-            }
-
-            if (!upgraded) {
-                Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
-            }
-
-            if (oldVersion < 51 && newVersion >= 51) {
-                Log_OC.i(SQL, "Entering in the #51 add show/hide to folderSync table");
-                db.beginTransaction();
-                try {
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.SYNCED_FOLDERS_TABLE_NAME +
-                                   ADD_COLUMN + ProviderTableMeta.SYNCED_FOLDER_HIDDEN + " INTEGER ");
-
-                    upgraded = true;
-                    db.setTransactionSuccessful();
-                } finally {
-                    db.endTransaction();
-                }
-            }
-
-            if (!upgraded) {
-                Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
-            }
-
-            if (oldVersion < 52 && newVersion >= 52) {
-                Log_OC.i(SQL, "Entering in the #52 add etag for directEditing to capability");
-                db.beginTransaction();
-                try {
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
-                                   ADD_COLUMN + ProviderTableMeta.CAPABILITIES_DIRECT_EDITING_ETAG + " TEXT ");
-
-                    upgraded = true;
-                    db.setTransactionSuccessful();
-                } finally {
-                    db.endTransaction();
-                }
-            }
-
-            if (!upgraded) {
-                Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
-            }
-
-            if (oldVersion < 53 && newVersion >= 53) {
-                Log_OC.i(SQL, "Entering in the #53 add rich workspace to file table");
-                db.beginTransaction();
-                try {
-                    if (!checkIfColumnExists(db, ProviderTableMeta.FILE_TABLE_NAME,
-                                             ProviderTableMeta.FILE_RICH_WORKSPACE)) {
-                        db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
-                                       ADD_COLUMN + ProviderTableMeta.FILE_RICH_WORKSPACE + " TEXT ");
-                    }
-                    upgraded = true;
-                    db.setTransactionSuccessful();
-                } finally {
-                    db.endTransaction();
-                }
-            }
-
-            if (!upgraded) {
-                Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
-            }
-
-            if (oldVersion < 54 && newVersion >= 54) {
-                Log_OC.i(SQL, "Entering in the #54 add synced.existing," +
-                    " rename uploads.force_overwrite to uploads.name_collision_policy");
-                db.beginTransaction();
-                try {
-                    // Add synced.existing
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.SYNCED_FOLDERS_TABLE_NAME +
-                                   ADD_COLUMN + ProviderTableMeta.SYNCED_FOLDER_EXISTING + " INTEGER "); // boolean
-
-
-                    // Rename uploads.force_overwrite to uploads.name_collision_policy
-                    String tmpTableName = ProviderTableMeta.UPLOADS_TABLE_NAME + "_old";
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.UPLOADS_TABLE_NAME + " RENAME TO " + tmpTableName);
-                    createUploadsTable(db);
-                    db.execSQL("INSERT INTO " + ProviderTableMeta.UPLOADS_TABLE_NAME + " (" +
-                                   ProviderTableMeta._ID + ", " +
-                                   ProviderTableMeta.UPLOADS_LOCAL_PATH + ", " +
-                                   ProviderTableMeta.UPLOADS_REMOTE_PATH + ", " +
-                                   ProviderTableMeta.UPLOADS_ACCOUNT_NAME + ", " +
-                                   ProviderTableMeta.UPLOADS_FILE_SIZE + ", " +
-                                   ProviderTableMeta.UPLOADS_STATUS + ", " +
-                                   ProviderTableMeta.UPLOADS_LOCAL_BEHAVIOUR + ", " +
-                                   ProviderTableMeta.UPLOADS_UPLOAD_TIME + ", " +
-                                   ProviderTableMeta.UPLOADS_NAME_COLLISION_POLICY + ", " +
-                                   ProviderTableMeta.UPLOADS_IS_CREATE_REMOTE_FOLDER + ", " +
-                                   ProviderTableMeta.UPLOADS_UPLOAD_END_TIMESTAMP + ", " +
-                                   ProviderTableMeta.UPLOADS_LAST_RESULT + ", " +
-                                   ProviderTableMeta.UPLOADS_IS_WHILE_CHARGING_ONLY + ", " +
-                                   ProviderTableMeta.UPLOADS_IS_WIFI_ONLY + ", " +
-                                   ProviderTableMeta.UPLOADS_CREATED_BY + ", " +
-                                   ProviderTableMeta.UPLOADS_FOLDER_UNLOCK_TOKEN +
-                                   ") " +
-                                   " SELECT " +
-                                   ProviderTableMeta._ID + ", " +
-                                   ProviderTableMeta.UPLOADS_LOCAL_PATH + ", " +
-                                   ProviderTableMeta.UPLOADS_REMOTE_PATH + ", " +
-                                   ProviderTableMeta.UPLOADS_ACCOUNT_NAME + ", " +
-                                   ProviderTableMeta.UPLOADS_FILE_SIZE + ", " +
-                                   ProviderTableMeta.UPLOADS_STATUS + ", " +
-                                   ProviderTableMeta.UPLOADS_LOCAL_BEHAVIOUR + ", " +
-                                   ProviderTableMeta.UPLOADS_UPLOAD_TIME + ", " +
-                                   "force_overwrite" + ", " + // See FileUploader.NameCollisionPolicy
-                                   ProviderTableMeta.UPLOADS_IS_CREATE_REMOTE_FOLDER + ", " +
-                                   ProviderTableMeta.UPLOADS_UPLOAD_END_TIMESTAMP + ", " +
-                                   ProviderTableMeta.UPLOADS_LAST_RESULT + ", " +
-                                   ProviderTableMeta.UPLOADS_IS_WHILE_CHARGING_ONLY + ", " +
-                                   ProviderTableMeta.UPLOADS_IS_WIFI_ONLY + ", " +
-                                   ProviderTableMeta.UPLOADS_CREATED_BY + ", " +
-                                   ProviderTableMeta.UPLOADS_FOLDER_UNLOCK_TOKEN +
-                                   " FROM " + tmpTableName);
-                    db.execSQL("DROP TABLE " + tmpTableName);
-
-                    upgraded = true;
-                    db.setTransactionSuccessful();
-                } finally {
-                    db.endTransaction();
-                }
-            }
-
-            if (!upgraded) {
-                Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
-            }
-
-            if (oldVersion < 55 && newVersion >= 55) {
-                Log_OC.i(SQL, "Entering in the #55 add synced.name_collision_policy.");
-                db.beginTransaction();
-                try {
-                    // Add synced.name_collision_policy
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.SYNCED_FOLDERS_TABLE_NAME +
-                                   ADD_COLUMN + ProviderTableMeta.SYNCED_FOLDER_NAME_COLLISION_POLICY + " INTEGER "); // integer
-
-                    // make sure all existing folders set to FileUploader.NameCollisionPolicy.ASK_USER.
-                    db.execSQL("UPDATE " + ProviderTableMeta.SYNCED_FOLDERS_TABLE_NAME + " SET " +
-                                   ProviderTableMeta.SYNCED_FOLDER_NAME_COLLISION_POLICY + " = " +
-                                   NameCollisionPolicy.ASK_USER.serialize());
-                    upgraded = true;
-                    db.setTransactionSuccessful();
-                } finally {
-                    db.endTransaction();
-                }
-            }
-
-            if (!upgraded) {
-                Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
-            }
-
-            if (oldVersion < 56 && newVersion >= 56) {
-                Log_OC.i(SQL, "Entering in the #56 add decrypted remote path");
-                db.beginTransaction();
-                try {
-                    // Add synced.name_collision_policy
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
-                                   ADD_COLUMN + ProviderTableMeta.FILE_PATH_DECRYPTED + " TEXT "); // strin
-
-                    upgraded = true;
-                    db.setTransactionSuccessful();
-                } finally {
-                    db.endTransaction();
-                }
-            }
-
-            if (!upgraded) {
-                Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
-            }
-
-            if (oldVersion < 57 && newVersion >= 57) {
-                Log_OC.i(SQL, "Entering in the #57 add etag for capabilities");
-                db.beginTransaction();
-                try {
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
-                                   ADD_COLUMN + ProviderTableMeta.CAPABILITIES_ETAG + " TEXT ");
-
-                    upgraded = true;
-                    db.setTransactionSuccessful();
-                } finally {
-                    db.endTransaction();
-                }
-            }
-
-            if (!upgraded) {
-                Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
-            }
-
-            if (oldVersion < 58 && newVersion >= 58) {
-                Log_OC.i(SQL, "Entering in the #58 add public link to share table");
-                db.beginTransaction();
-                try {
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.OCSHARES_TABLE_NAME +
-                                   ADD_COLUMN + ProviderTableMeta.OCSHARES_SHARE_LINK + " TEXT ");
-
-                    upgraded = true;
-                    db.setTransactionSuccessful();
-                } finally {
-                    db.endTransaction();
-                }
-            }
-
-            if (!upgraded) {
-                Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
-            }
-
-            if (oldVersion < 59 && newVersion >= 59) {
-                Log_OC.i(SQL, "Entering in the #59 add public label to share table");
-                db.beginTransaction();
-                try {
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.OCSHARES_TABLE_NAME +
-                                   ADD_COLUMN + ProviderTableMeta.OCSHARES_SHARE_LABEL + " TEXT ");
-
-                    upgraded = true;
-                    db.setTransactionSuccessful();
-                } finally {
-                    db.endTransaction();
-                }
-            }
-
-            if (!upgraded) {
-                Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
-            }
-
-            if (oldVersion < 60 && newVersion >= 60) {
-                Log_OC.i(SQL, "Entering in the #60 add user status to capability table");
-                db.beginTransaction();
-                try {
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
-                                   ADD_COLUMN + ProviderTableMeta.CAPABILITIES_USER_STATUS + " INTEGER ");
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
-                                   ADD_COLUMN + ProviderTableMeta.CAPABILITIES_USER_STATUS_SUPPORTS_EMOJI + " INTEGER ");
-
-                    upgraded = true;
-                    db.setTransactionSuccessful();
-                } finally {
-                    db.endTransaction();
-                }
-            }
-
-            if (!upgraded) {
-                Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
-            }
-
-            if (oldVersion < 61 && newVersion >= 61) {
-                Log_OC.i(SQL, "Entering in the #61 reset eTag to force capability refresh");
-                db.beginTransaction();
-                try {
-                    db.execSQL("UPDATE capabilities SET etag = '' WHERE 1=1");
-
-                    upgraded = true;
-                    db.setTransactionSuccessful();
-                } finally {
-                    db.endTransaction();
-                }
-            }
-
-            if (!upgraded) {
-                Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
-            }
-
-            if (oldVersion < 62 && newVersion >= 62) {
-                Log_OC.i(SQL, "Entering in the #62 add logo to capability");
-                db.beginTransaction();
-                try {
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
-                                   ADD_COLUMN + ProviderTableMeta.CAPABILITIES_SERVER_LOGO + " TEXT ");
-
-                    // force refresh
-                    db.execSQL("UPDATE capabilities SET etag = '' WHERE 1=1");
-
-                    upgraded = true;
-                    db.setTransactionSuccessful();
-                } finally {
-                    db.endTransaction();
-                }
-            }
-
-            if (oldVersion < 63 && newVersion >= 63) {
-                Log_OC.i(SQL, "Adding file locking columns");
-                db.beginTransaction();
-                try {
-                    // locking capabilities
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME + ADD_COLUMN + ProviderTableMeta.CAPABILITIES_FILES_LOCKING_VERSION + " TEXT ");
-                    // force refresh
-                    db.execSQL("UPDATE capabilities SET etag = '' WHERE 1=1");
-                    // locking properties
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
-                                   ADD_COLUMN + ProviderTableMeta.FILE_LOCKED + " INTEGER "); // boolean
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
-                                   ADD_COLUMN + ProviderTableMeta.FILE_LOCK_TYPE + " INTEGER ");
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
-                                   ADD_COLUMN + ProviderTableMeta.FILE_LOCK_OWNER + " TEXT ");
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
-                                   ADD_COLUMN + ProviderTableMeta.FILE_LOCK_OWNER_DISPLAY_NAME + " TEXT ");
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
-                                   ADD_COLUMN + ProviderTableMeta.FILE_LOCK_OWNER_EDITOR + " TEXT ");
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
-                                   ADD_COLUMN + ProviderTableMeta.FILE_LOCK_TIMESTAMP + " INTEGER ");
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
-                                   ADD_COLUMN + ProviderTableMeta.FILE_LOCK_TIMEOUT + " INTEGER ");
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
-                                   ADD_COLUMN + ProviderTableMeta.FILE_LOCK_TOKEN + " TEXT ");
-                    db.execSQL("UPDATE " + ProviderTableMeta.FILE_TABLE_NAME + " SET " + ProviderTableMeta.FILE_ETAG + " = '' WHERE 1=1");
-
-                    db.setTransactionSuccessful();
-                } finally {
-                    db.endTransaction();
-                }
-            }
-
-            if (!upgraded) {
-                Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
-            }
-
-            if (oldVersion < 64 && newVersion >= 64) {
-                Log_OC.i(SQL, "Entering in the #64 add metadata size to files");
-                db.beginTransaction();
-                try {
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
-                                   ADD_COLUMN + ProviderTableMeta.FILE_METADATA_SIZE + " TEXT ");
-
-                    upgraded = true;
-                    db.setTransactionSuccessful();
-                } finally {
-                    db.endTransaction();
-                }
-            }
-
-            if (!upgraded) {
-                Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
-            }
-        }
-    }
 }