Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/android.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÁlvaro Brey <alvaro.brey@nextcloud.com>2022-11-07 21:19:54 +0300
committerÁlvaro Brey <alvaro.brey@nextcloud.com>2022-11-11 01:24:50 +0300
commit798930ae3a9fc21dd8e7d4c70733766c6bf3b7b9 (patch)
treeaeea1f38a4360cfa37fb4ff9497be65a90e60cfd
parentf725c2de5220c0153ea3b054f8effbae9141847f (diff)
Delete database migration code under database v24 (app v2.0.0)enter-the-room
Migration from such old app versions is broken anyway, not only in the database, but also in sharedprefs Additionally, configure destructive migration for unsupported versions in Room Signed-off-by: Álvaro Brey <alvaro.brey@nextcloud.com>
-rw-r--r--app/src/main/java/com/nextcloud/client/database/DatabaseModule.kt1
-rw-r--r--app/src/main/java/com/nextcloud/client/database/migrations/LegacyMigration.kt4
-rw-r--r--app/src/main/java/com/nextcloud/client/database/migrations/LegacyMigrationHelper.java452
3 files changed, 4 insertions, 453 deletions
diff --git a/app/src/main/java/com/nextcloud/client/database/DatabaseModule.kt b/app/src/main/java/com/nextcloud/client/database/DatabaseModule.kt
index 8a24049f7f..608cbf4bfd 100644
--- a/app/src/main/java/com/nextcloud/client/database/DatabaseModule.kt
+++ b/app/src/main/java/com/nextcloud/client/database/DatabaseModule.kt
@@ -43,6 +43,7 @@ class DatabaseModule {
.databaseBuilder(context, NextcloudDatabase::class.java, ProviderMeta.DB_NAME)
.addLegacyMigrations(context, clock)
.addMigrations(RoomMigration())
+ .fallbackToDestructiveMigration()
.build()
}
}
diff --git a/app/src/main/java/com/nextcloud/client/database/migrations/LegacyMigration.kt b/app/src/main/java/com/nextcloud/client/database/migrations/LegacyMigration.kt
index a5491f097c..91ec2dd0eb 100644
--- a/app/src/main/java/com/nextcloud/client/database/migrations/LegacyMigration.kt
+++ b/app/src/main/java/com/nextcloud/client/database/migrations/LegacyMigration.kt
@@ -29,6 +29,8 @@ import androidx.sqlite.db.SupportSQLiteDatabase
import com.nextcloud.client.core.Clock
import com.nextcloud.client.database.NextcloudDatabase
+private const val MIN_SUPPORTED_DB_VERSION = 24
+
/**
* Migrations for DB versions before Room was introduced
*/
@@ -54,7 +56,7 @@ fun RoomDatabase.Builder<NextcloudDatabase>.addLegacyMigrations(
context: Context,
clock: Clock
): RoomDatabase.Builder<NextcloudDatabase> {
- (1 until NextcloudDatabase.FIRST_ROOM_DB_VERSION - 1)
+ (MIN_SUPPORTED_DB_VERSION until NextcloudDatabase.FIRST_ROOM_DB_VERSION - 1)
.map { from -> LegacyMigration(from, from + 1, context, clock) }
.forEach { migration -> this.addMigrations(migration) }
return this
diff --git a/app/src/main/java/com/nextcloud/client/database/migrations/LegacyMigrationHelper.java b/app/src/main/java/com/nextcloud/client/database/migrations/LegacyMigrationHelper.java
index f0872630b2..e20f32cd56 100644
--- a/app/src/main/java/com/nextcloud/client/database/migrations/LegacyMigrationHelper.java
+++ b/app/src/main/java/com/nextcloud/client/database/migrations/LegacyMigrationHelper.java
@@ -76,458 +76,6 @@ public class LegacyMigrationHelper {
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");