Convert ThumbKeyMigration to AutoMigrationSpec
This commit is contained in:
1 parent
c73ca48e35
commit
4e6f906903
2 files changed
+12
-12
No files matched your search
@@ -27,7 +27,6 @@ import com.hippo.ehviewer.dao.BasicDao
|
||||
import com.hippo.ehviewer.dao.DownloadDirname
|
||||
import com.hippo.ehviewer.dao.DownloadInfo
|
||||
import com.hippo.ehviewer.dao.DownloadLabel
|
||||
import com.hippo.ehviewer.dao.EHDB_MIGRATION_4_5
|
||||
import com.hippo.ehviewer.dao.EhDatabase
|
||||
import com.hippo.ehviewer.dao.Filter
|
||||
import com.hippo.ehviewer.dao.HistoryInfo
|
||||
@@ -400,7 +399,6 @@ object EhDB {
|
||||
runCatching {
|
||||
val oldDB = databaseBuilder(context, EhDatabase::class.java, "tmp.db")
|
||||
.createFromInputStream { context.contentResolver.openInputStream(uri) }
|
||||
.addMigrations(EHDB_MIGRATION_4_5)
|
||||
.build()
|
||||
|
||||
// Download label
|
||||
|
||||
@@ -7,11 +7,13 @@ import androidx.room.DeleteTable
|
||||
import androidx.room.Room
|
||||
import androidx.room.RoomDatabase
|
||||
import androidx.room.migration.AutoMigrationSpec
|
||||
import androidx.room.migration.Migration
|
||||
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
|
||||
val EHDB_MIGRATION_4_5 = object : Migration(4, 5) {
|
||||
override fun migrate(db: SupportSQLiteDatabase) {
|
||||
@DeleteTable(tableName = "BOOKMARKS")
|
||||
class DropBookMarkDao : AutoMigrationSpec
|
||||
|
||||
class ThumbKeyMigration : AutoMigrationSpec {
|
||||
override fun onPostMigrate(db: SupportSQLiteDatabase) {
|
||||
val needMigrationTables = arrayOf(
|
||||
"DOWNLOADS",
|
||||
"HISTORY",
|
||||
@@ -30,14 +32,16 @@ val EHDB_MIGRATION_4_5 = object : Migration(4, 5) {
|
||||
}
|
||||
}
|
||||
|
||||
@DeleteTable(tableName = "BOOKMARKS")
|
||||
class A : AutoMigrationSpec
|
||||
|
||||
@Database(
|
||||
entities = [DownloadInfo::class, DownloadLabel::class, DownloadDirname::class, Filter::class, HistoryInfo::class, LocalFavoriteInfo::class, QuickSearch::class],
|
||||
version = 7,
|
||||
exportSchema = true,
|
||||
autoMigrations = [
|
||||
AutoMigration(
|
||||
from = 4,
|
||||
to = 5,
|
||||
spec = ThumbKeyMigration::class,
|
||||
),
|
||||
AutoMigration(
|
||||
from = 5,
|
||||
to = 6,
|
||||
@@ -45,7 +49,7 @@ class A : AutoMigrationSpec
|
||||
AutoMigration(
|
||||
from = 6,
|
||||
to = 7,
|
||||
spec = A::class,
|
||||
spec = DropBookMarkDao::class,
|
||||
),
|
||||
],
|
||||
)
|
||||
@@ -76,9 +80,7 @@ abstract class CookiesDatabase : RoomDatabase() {
|
||||
|
||||
fun buildMainDB(context: Context): EhDatabase {
|
||||
// TODO: Remove allowMainThreadQueries
|
||||
return Room.databaseBuilder(context, EhDatabase::class.java, "eh.db").allowMainThreadQueries()
|
||||
.addMigrations(EHDB_MIGRATION_4_5)
|
||||
.build()
|
||||
return Room.databaseBuilder(context, EhDatabase::class.java, "eh.db").allowMainThreadQueries().build()
|
||||
}
|
||||
|
||||
fun buildCookiesDB(context: Context): CookiesDatabase {
|
||||
|
||||
Reference in new issue
Block a user