Skip to content

Commit d97218f

Browse files
Merge pull request #15015 from nextcloud/backport/15010/stable-3.32
[stable-3.32] BugFix - Add Manual Migration 88 to 89
2 parents c0158f7 + 10dd64a commit d97218f

File tree

4 files changed

+73
-1
lines changed

4 files changed

+73
-1
lines changed

app/src/main/java/com/nextcloud/client/database/NextcloudDatabase.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import com.nextcloud.client.database.entity.SyncedFolderEntity
2929
import com.nextcloud.client.database.entity.UploadEntity
3030
import com.nextcloud.client.database.entity.VirtualEntity
3131
import com.nextcloud.client.database.migrations.DatabaseMigrationUtil
32+
import com.nextcloud.client.database.migrations.MIGRATION_88_89
3233
import com.nextcloud.client.database.migrations.Migration67to68
3334
import com.nextcloud.client.database.migrations.RoomMigration
3435
import com.nextcloud.client.database.migrations.addLegacyMigrations
@@ -72,7 +73,7 @@ import com.owncloud.android.db.ProviderMeta
7273
AutoMigration(from = 85, to = 86, spec = DatabaseMigrationUtil.ResetCapabilitiesPostMigration::class),
7374
AutoMigration(from = 86, to = 87, spec = DatabaseMigrationUtil.ResetCapabilitiesPostMigration::class),
7475
AutoMigration(from = 87, to = 88, spec = DatabaseMigrationUtil.ResetCapabilitiesPostMigration::class),
75-
AutoMigration(from = 88, to = 89),
76+
// manual migration used for 88 to 89
7677
AutoMigration(from = 89, to = 90)
7778
],
7879
exportSchema = true
@@ -106,6 +107,7 @@ abstract class NextcloudDatabase : RoomDatabase() {
106107
.addLegacyMigrations(clock, context)
107108
.addMigrations(RoomMigration())
108109
.addMigrations(Migration67to68())
110+
.addMigrations(MIGRATION_88_89)
109111
.build()
110112
}
111113
return instance!!

app/src/main/java/com/nextcloud/client/database/migrations/DatabaseMigrationUtil.kt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ package com.nextcloud.client.database.migrations
1010
import androidx.room.DeleteColumn
1111
import androidx.room.migration.AutoMigrationSpec
1212
import androidx.sqlite.db.SupportSQLiteDatabase
13+
import com.nextcloud.client.database.migrations.model.SQLiteColumnType
1314

1415
object DatabaseMigrationUtil {
1516

@@ -18,6 +19,32 @@ object DatabaseMigrationUtil {
1819
const val TYPE_INTEGER_PRIMARY_KEY = "INTEGER PRIMARY KEY"
1920
const val KEYWORD_NOT_NULL = "NOT NULL"
2021

22+
fun addColumnIfNotExists(
23+
db: SupportSQLiteDatabase,
24+
tableName: String,
25+
columnName: String,
26+
columnType: SQLiteColumnType
27+
) {
28+
val cursor = db.query("PRAGMA table_info($tableName)")
29+
var columnExists = false
30+
31+
while (cursor.moveToNext()) {
32+
val nameIndex = cursor.getColumnIndex("name")
33+
if (nameIndex != -1) {
34+
val existingColumnName = cursor.getString(nameIndex)
35+
if (existingColumnName == columnName) {
36+
columnExists = true
37+
break
38+
}
39+
}
40+
}
41+
cursor.close()
42+
43+
if (!columnExists) {
44+
db.execSQL("ALTER TABLE $tableName ADD COLUMN `$columnName` ${columnType.value}")
45+
}
46+
}
47+
2148
/**
2249
* Utility method to add or remove columns from a table
2350
*
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Nextcloud - Android Client
3+
*
4+
* SPDX-FileCopyrightText: 2025 Alper Ozturk <[email protected]>
5+
* SPDX-License-Identifier: AGPL-3.0-or-later
6+
*/
7+
8+
package com.nextcloud.client.database.migrations
9+
10+
import androidx.room.migration.Migration
11+
import androidx.sqlite.db.SupportSQLiteDatabase
12+
import com.nextcloud.client.database.migrations.model.SQLiteColumnType
13+
import com.owncloud.android.db.ProviderMeta.ProviderTableMeta
14+
15+
val MIGRATION_88_89 = object : Migration(88, 89) {
16+
override fun migrate(database: SupportSQLiteDatabase) {
17+
DatabaseMigrationUtil.addColumnIfNotExists(
18+
database,
19+
ProviderTableMeta.FILE_TABLE_NAME,
20+
ProviderTableMeta.FILE_UPLOADED,
21+
SQLiteColumnType.INTEGER_DEFAULT_NULL
22+
)
23+
DatabaseMigrationUtil.addColumnIfNotExists(
24+
database,
25+
ProviderTableMeta.CAPABILITIES_TABLE_NAME,
26+
ProviderTableMeta.CAPABILITIES_NOTES_FOLDER_PATH,
27+
SQLiteColumnType.TEXT_DEFAULT_NULL
28+
)
29+
}
30+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
* Nextcloud - Android Client
3+
*
4+
* SPDX-FileCopyrightText: 2025 Alper Ozturk <[email protected]>
5+
* SPDX-License-Identifier: AGPL-3.0-or-later
6+
*/
7+
8+
package com.nextcloud.client.database.migrations.model
9+
10+
enum class SQLiteColumnType(val value: String) {
11+
INTEGER_DEFAULT_NULL("INTEGER DEFAULT NULL"),
12+
TEXT_DEFAULT_NULL("TEXT DEFAULT NULL")
13+
}

0 commit comments

Comments
 (0)