Skip to content

Commit a136902

Browse files
committed
Fix database migration to DB version 38
1 parent fb3dc46 commit a136902

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

owncloudApp/src/main/java/com/owncloud/android/providers/FileContentProvider.kt

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@ import android.os.CancellationSignal
4646
import android.os.ParcelFileDescriptor
4747
import android.provider.BaseColumns
4848
import android.text.TextUtils
49+
import android.util.Log
4950
import androidx.sqlite.db.SupportSQLiteDatabase
5051
import androidx.sqlite.db.SupportSQLiteQueryBuilder
52+
import androidx.work.WorkManager
5153
import com.owncloud.android.MainApp
5254
import com.owncloud.android.R
5355
import com.owncloud.android.data.Executors
@@ -56,14 +58,12 @@ import com.owncloud.android.data.ProviderMeta
5658
import com.owncloud.android.data.capabilities.datasources.implementation.OCLocalCapabilitiesDataSource
5759
import com.owncloud.android.data.capabilities.datasources.implementation.OCLocalCapabilitiesDataSource.Companion.toModel
5860
import com.owncloud.android.data.capabilities.db.OCCapabilityEntity
59-
import com.owncloud.android.data.files.db.FileDao
6061
import com.owncloud.android.data.files.db.OCFileEntity
6162
import com.owncloud.android.data.folderbackup.datasources.FolderBackupLocalDataSource
6263
import com.owncloud.android.data.migrations.CameraUploadsMigrationToRoom
6364
import com.owncloud.android.data.preferences.datasources.SharedPreferencesProvider
6465
import com.owncloud.android.data.sharing.shares.db.OCShareEntity
6566
import com.owncloud.android.data.transfers.db.OCTransferEntity
66-
import com.owncloud.android.data.transfers.db.TransferDao
6767
import com.owncloud.android.db.ProviderMeta.ProviderTableMeta
6868
import com.owncloud.android.domain.camerauploads.model.UploadBehavior
6969
import com.owncloud.android.domain.files.model.LIST_MIME_DIR
@@ -284,6 +284,8 @@ class FileContentProvider(val executors: Executors = Executors()) : ContentProvi
284284

285285
override fun onCreate(): Boolean {
286286
dbHelper = DataBaseHelper(context)
287+
// This sentence is for opening the database, which is necessary to perform the migration correctly to DB version 38
288+
dbHelper.writableDatabase
287289

288290
val authority = context?.resources?.getString(R.string.authority)
289291
uriMatcher = UriMatcher(UriMatcher.NO_MATCH)
@@ -541,7 +543,7 @@ class FileContentProvider(val executors: Executors = Executors()) : ContentProvi
541543
}
542544

543545
override fun onUpgrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
544-
Timber.i("SQL : Entering in onUpgrade")
546+
Log.i("SQLiteOpenHelper", "SQL : Entering in onUpgrade")
545547
var upgraded = false
546548

547549
if (oldVersion == 1 && newVersion >= 2) {
@@ -1050,8 +1052,8 @@ class FileContentProvider(val executors: Executors = Executors()) : ContentProvi
10501052
}
10511053
}
10521054

1053-
if (oldVersion < 37 && newVersion >= 37) {
1054-
Timber.i("SQL : Entering in #37 to migrate files and uploads from SQLite to Room")
1055+
if (oldVersion < 38 && newVersion >= 38) {
1056+
Timber.i("SQL : Entering in #38 to migrate files and uploads from SQLite to Room")
10551057
db.beginTransaction()
10561058

10571059
try {
@@ -1073,7 +1075,7 @@ class FileContentProvider(val executors: Executors = Executors()) : ContentProvi
10731075
} while (cursorFiles.moveToNext())
10741076

10751077
// Insert file list to the new files table in new database
1076-
val ocFileDao: FileDao by inject()
1078+
val ocFileDao = OwncloudDatabase.getDatabase(context!!).fileDao()
10771079
executors.diskIO().execute {
10781080
for (file in files) {
10791081
ocFileDao.mergeRemoteAndLocalFile(file)
@@ -1103,7 +1105,7 @@ class FileContentProvider(val executors: Executors = Executors()) : ContentProvi
11031105
} while (cursorUploads.moveToNext())
11041106

11051107
// Insert uploads list to the new transfers table in new database
1106-
val ocTransferDao: TransferDao by inject()
1108+
val ocTransferDao = OwncloudDatabase.getDatabase(context!!).transferDao()
11071109
executors.diskIO().execute {
11081110
for (upload in uploads) {
11091111
ocTransferDao.insert(upload)
@@ -1112,7 +1114,7 @@ class FileContentProvider(val executors: Executors = Executors()) : ContentProvi
11121114
upload.createdBy != UploadEnqueuedBy.ENQUEUED_AS_CAMERA_UPLOAD_VIDEO.ordinal
11131115
) {
11141116
val localFile = File(upload.localPath)
1115-
val uploadFileFromSystemUseCase: UploadFileFromSystemUseCase by inject()
1117+
val uploadFileFromSystemUseCase = UploadFileFromSystemUseCase(WorkManager.getInstance(context!!))
11161118
uploadFileFromSystemUseCase.execute(
11171119
UploadFileFromSystemUseCase.Params(
11181120
accountName = upload.accountName,
@@ -1134,6 +1136,15 @@ class FileContentProvider(val executors: Executors = Executors()) : ContentProvi
11341136
// Drop old capabilities table from old database
11351137
db.execSQL("DROP TABLE IF EXISTS " + ProviderTableMeta.CAPABILITIES_TABLE_NAME + ";")
11361138

1139+
// Drop old camera uploads sync table from old database
1140+
db.execSQL("DROP TABLE IF EXISTS " + ProviderTableMeta.CAMERA_UPLOADS_SYNC_TABLE_NAME + ";")
1141+
1142+
// Drop old user avatars table from old database
1143+
db.execSQL("DROP TABLE IF EXISTS " + ProviderTableMeta.USER_AVATARS__TABLE_NAME + ";")
1144+
1145+
// Drop old user quotas table from old database
1146+
db.execSQL("DROP TABLE IF EXISTS " + ProviderTableMeta.USER_QUOTAS_TABLE_NAME + ";")
1147+
11371148
db.setTransactionSuccessful()
11381149
upgraded = true
11391150
} finally {

0 commit comments

Comments
 (0)