From dc9cc6ade5c5d684f8760009134e49eb0c26cf01 Mon Sep 17 00:00:00 2001 From: ZetaTom <70907959+ZetaTom@users.noreply.github.com> Date: Mon, 6 Nov 2023 15:36:20 +0100 Subject: [PATCH] Fix database migration Signed-off-by: ZetaTom <70907959+ZetaTom@users.noreply.github.com> --- .../74.json | 56 ++++++++++--------- .../client/database/NextcloudDatabase.kt | 6 +- .../migrations/DatabaseMigrationUtil.kt | 11 ++++ .../database/migrations/Migration73to74.kt | 38 ------------- 4 files changed, 45 insertions(+), 66 deletions(-) delete mode 100644 app/src/main/java/com/nextcloud/client/database/migrations/Migration73to74.kt diff --git a/app/schemas/com.nextcloud.client.database.NextcloudDatabase/74.json b/app/schemas/com.nextcloud.client.database.NextcloudDatabase/74.json index 5f8b60cfd6..d37b3654d9 100644 --- a/app/schemas/com.nextcloud.client.database.NextcloudDatabase/74.json +++ b/app/schemas/com.nextcloud.client.database.NextcloudDatabase/74.json @@ -1,18 +1,18 @@ { "formatVersion": 1, "database": { - "version": 74, - "identityHash": "bc3fbd9985959e167fdd38198dd480b5", - "entities": [ + "version": 74, + "identityHash": "7e73c045ac6d52d6c7c1626eefbc21e9", + "entities": [ + { + "tableName": "arbitrary_data", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`_id` INTEGER PRIMARY KEY AUTOINCREMENT, `cloud_id` TEXT, `key` TEXT, `value` TEXT)", + "fields": [ { - "tableName": "arbitrary_data", - "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`_id` INTEGER PRIMARY KEY AUTOINCREMENT, `cloud_id` TEXT, `key` TEXT, `value` TEXT)", - "fields": [ - { - "fieldPath": "id", - "columnName": "_id", - "affinity": "INTEGER", - "notNull": false + "fieldPath": "id", + "columnName": "_id", + "affinity": "INTEGER", + "notNull": false }, { "fieldPath": "cloudId", @@ -42,19 +42,19 @@ "indices": [], "foreignKeys": [] }, + { + "tableName": "capabilities", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`_id` INTEGER PRIMARY KEY AUTOINCREMENT, `account` TEXT, `version_mayor` INTEGER, `version_minor` INTEGER, `version_micro` INTEGER, `version_string` TEXT, `version_edition` TEXT, `extended_support` INTEGER, `core_pollinterval` INTEGER, `sharing_api_enabled` INTEGER, `sharing_public_enabled` INTEGER, `sharing_public_password_enforced` INTEGER, `sharing_public_expire_date_enabled` INTEGER, `sharing_public_expire_date_days` INTEGER, `sharing_public_expire_date_enforced` INTEGER, `sharing_public_send_mail` INTEGER, `sharing_public_upload` INTEGER, `sharing_user_send_mail` INTEGER, `sharing_resharing` INTEGER, `sharing_federation_outgoing` INTEGER, `sharing_federation_incoming` INTEGER, `files_bigfilechunking` INTEGER, `files_undelete` INTEGER, `files_versioning` INTEGER, `external_links` INTEGER, `server_name` TEXT, `server_color` TEXT, `server_text_color` TEXT, `server_element_color` TEXT, `server_slogan` TEXT, `server_logo` TEXT, `background_url` TEXT, `end_to_end_encryption` INTEGER, `end_to_end_encryption_keys_exist` INTEGER, `activity` INTEGER, `background_default` INTEGER, `background_plain` INTEGER, `richdocument` INTEGER, `richdocument_mimetype_list` TEXT, `richdocument_direct_editing` INTEGER, `richdocument_direct_templates` INTEGER, `richdocument_optional_mimetype_list` TEXT, `sharing_public_ask_for_optional_password` INTEGER, `richdocument_product_name` TEXT, `direct_editing_etag` TEXT, `user_status` INTEGER, `user_status_supports_emoji` INTEGER, `etag` TEXT, `files_locking_version` TEXT, `groupfolders` INTEGER, `drop_account` INTEGER)", + "fields": [ { - "tableName": "capabilities", - "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`_id` INTEGER PRIMARY KEY AUTOINCREMENT, `account` TEXT, `version_mayor` INTEGER, `version_minor` INTEGER, `version_micro` INTEGER, `version_string` TEXT, `version_edition` TEXT, `extended_support` INTEGER, `core_pollinterval` INTEGER, `sharing_api_enabled` INTEGER, `sharing_public_enabled` INTEGER, `sharing_public_password_enforced` INTEGER, `sharing_public_expire_date_enabled` INTEGER, `sharing_public_expire_date_days` INTEGER, `sharing_public_expire_date_enforced` INTEGER, `sharing_public_send_mail` INTEGER, `sharing_public_upload` INTEGER, `sharing_user_send_mail` INTEGER, `sharing_resharing` INTEGER, `sharing_federation_outgoing` INTEGER, `sharing_federation_incoming` INTEGER, `files_bigfilechunking` INTEGER, `files_undelete` INTEGER, `files_versioning` INTEGER, `external_links` INTEGER, `server_name` TEXT, `server_color` TEXT, `server_text_color` TEXT, `server_element_color` TEXT, `server_slogan` TEXT, `server_logo` TEXT, `background_url` TEXT, `end_to_end_encryption` INTEGER, `end_to_end_encryption_keys_exist` INTEGER, `activity` INTEGER, `background_default` INTEGER, `background_plain` INTEGER, `richdocument` INTEGER, `richdocument_mimetype_list` TEXT, `richdocument_direct_editing` INTEGER, `richdocument_direct_templates` INTEGER, `richdocument_optional_mimetype_list` TEXT, `sharing_public_ask_for_optional_password` INTEGER, `richdocument_product_name` TEXT, `direct_editing_etag` TEXT, `user_status` INTEGER, `user_status_supports_emoji` INTEGER, `etag` TEXT, `files_locking_version` TEXT, `groupfolders` INTEGER)", - "fields": [ - { - "fieldPath": "id", - "columnName": "_id", - "affinity": "INTEGER", - "notNull": false - }, - { - "fieldPath": "accountName", - "columnName": "account", + "fieldPath": "id", + "columnName": "_id", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "accountName", + "columnName": "account", "affinity": "TEXT", "notNull": false }, @@ -345,6 +345,12 @@ "columnName": "groupfolders", "affinity": "INTEGER", "notNull": false + }, + { + "fieldPath": "dropAccount", + "columnName": "drop_account", + "affinity": "INTEGER", + "notNull": false } ], "primaryKey": { @@ -1149,7 +1155,7 @@ "views": [], "setupQueries": [ "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)", - "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'bc3fbd9985959e167fdd38198dd480b5')" + "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '7e73c045ac6d52d6c7c1626eefbc21e9')" ] } -} +} \ No newline at end of file diff --git a/app/src/main/java/com/nextcloud/client/database/NextcloudDatabase.kt b/app/src/main/java/com/nextcloud/client/database/NextcloudDatabase.kt index a0a97ae0a5..bb2ea933cc 100644 --- a/app/src/main/java/com/nextcloud/client/database/NextcloudDatabase.kt +++ b/app/src/main/java/com/nextcloud/client/database/NextcloudDatabase.kt @@ -40,9 +40,9 @@ import com.nextcloud.client.database.entity.ShareEntity import com.nextcloud.client.database.entity.SyncedFolderEntity import com.nextcloud.client.database.entity.UploadEntity import com.nextcloud.client.database.entity.VirtualEntity +import com.nextcloud.client.database.migrations.DatabaseMigrationUtil import com.nextcloud.client.database.migrations.Migration67to68 import com.nextcloud.client.database.migrations.Migration70to71 -import com.nextcloud.client.database.migrations.Migration73to74 import com.nextcloud.client.database.migrations.RoomMigration import com.nextcloud.client.database.migrations.addLegacyMigrations import com.owncloud.android.db.ProviderMeta @@ -66,7 +66,8 @@ import com.owncloud.android.db.ProviderMeta AutoMigration(from = 68, to = 69), AutoMigration(from = 69, to = 70), AutoMigration(from = 71, to = 72), - AutoMigration(from = 72, to = 73) + AutoMigration(from = 72, to = 73), + AutoMigration(from = 73, to = 74, spec = DatabaseMigrationUtil.ResetCapabilitiesPostMigration::class) ], exportSchema = true ) @@ -97,7 +98,6 @@ abstract class NextcloudDatabase : RoomDatabase() { .addMigrations(RoomMigration()) .addMigrations(Migration67to68()) .addMigrations(Migration70to71()) - .addMigrations(Migration73to74()) .fallbackToDestructiveMigration() .build() } diff --git a/app/src/main/java/com/nextcloud/client/database/migrations/DatabaseMigrationUtil.kt b/app/src/main/java/com/nextcloud/client/database/migrations/DatabaseMigrationUtil.kt index 96d3379e1e..90f497a616 100644 --- a/app/src/main/java/com/nextcloud/client/database/migrations/DatabaseMigrationUtil.kt +++ b/app/src/main/java/com/nextcloud/client/database/migrations/DatabaseMigrationUtil.kt @@ -22,6 +22,7 @@ package com.nextcloud.client.database.migrations +import androidx.room.migration.AutoMigrationSpec import androidx.sqlite.db.SupportSQLiteDatabase object DatabaseMigrationUtil { @@ -102,4 +103,14 @@ object DatabaseMigrationUtil { database.execSQL("DROP TABLE $tableName") database.execSQL("ALTER TABLE $newTableTempName RENAME TO $tableName") } + + /** + * Room AutoMigrationSpec to reset capabilities post migration. + */ + class ResetCapabilitiesPostMigration : AutoMigrationSpec { + override fun onPostMigrate(db: SupportSQLiteDatabase) { + resetCapabilities(db) + super.onPostMigrate(db) + } + } } diff --git a/app/src/main/java/com/nextcloud/client/database/migrations/Migration73to74.kt b/app/src/main/java/com/nextcloud/client/database/migrations/Migration73to74.kt deleted file mode 100644 index afb1f7d398..0000000000 --- a/app/src/main/java/com/nextcloud/client/database/migrations/Migration73to74.kt +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Nextcloud Android client application - * - * @author Álvaro Brey - * Copyright (C) 2023 Álvaro Brey - * Copyright (C) 2023 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 . - * - */ - -package com.nextcloud.client.database.migrations - -import androidx.room.migration.Migration -import androidx.sqlite.db.SupportSQLiteDatabase - -/** - * Migration from version 73 to 74. - * - * resets capabilities to show groupfolder - */ -@Suppress("MagicNumber") -class Migration73to74 : Migration(73, 74) { - override fun migrate(database: SupportSQLiteDatabase) { - DatabaseMigrationUtil.resetCapabilities(database) - } -}