From eb2a904b618bcbecd1311fa0db3809425d91d8d5 Mon Sep 17 00:00:00 2001 From: Andreas Date: Sun, 3 Jul 2022 17:48:59 +0200 Subject: [PATCH] Remove SQLiteOpenHelper as database is migrated to SQLDelight (#7448) --- .../java/eu/kanade/tachiyomi/AppModule.kt | 30 ++++++---------- .../tachiyomi/data/database/DbOpenCallback.kt | 34 ------------------- 2 files changed, 11 insertions(+), 53 deletions(-) delete mode 100644 app/src/main/java/eu/kanade/tachiyomi/data/database/DbOpenCallback.kt diff --git a/app/src/main/java/eu/kanade/tachiyomi/AppModule.kt b/app/src/main/java/eu/kanade/tachiyomi/AppModule.kt index a5c3aad2fb..bee6ebce2c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/AppModule.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/AppModule.kt @@ -3,7 +3,6 @@ package eu.kanade.tachiyomi import android.app.Application import android.os.Build import androidx.core.content.ContextCompat -import androidx.sqlite.db.SupportSQLiteOpenHelper import androidx.sqlite.db.framework.FrameworkSQLiteOpenHelperFactory import com.squareup.sqldelight.android.AndroidSqliteDriver import com.squareup.sqldelight.db.SqlDriver @@ -15,7 +14,6 @@ import eu.kanade.data.dateAdapter import eu.kanade.data.listOfStringsAdapter import eu.kanade.tachiyomi.data.cache.ChapterCache import eu.kanade.tachiyomi.data.cache.CoverCache -import eu.kanade.tachiyomi.data.database.DbOpenCallback import eu.kanade.tachiyomi.data.download.DownloadManager import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.saver.ImageSaver @@ -37,24 +35,18 @@ class AppModule(val app: Application) : InjektModule { override fun InjektRegistrar.registerInjectables() { addSingleton(app) - // This is used to allow incremental migration from Storio - addSingletonFactory { - val configuration = SupportSQLiteOpenHelper.Configuration.builder(app) - .callback(DbOpenCallback()) - .name(DbOpenCallback.DATABASE_FILENAME) - .noBackupDirectory(false) - .build() - - if (BuildConfig.DEBUG && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - // Support database inspector in Android Studio - FrameworkSQLiteOpenHelperFactory().create(configuration) - } else { - RequerySQLiteOpenHelperFactory().create(configuration) - } - } - addSingletonFactory { - AndroidSqliteDriver(openHelper = get()) + AndroidSqliteDriver( + schema = Database.Schema, + context = app, + name = "tachiyomi.db", + factory = if (BuildConfig.DEBUG && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + // Support database inspector in Android Studio + FrameworkSQLiteOpenHelperFactory() + } else { + RequerySQLiteOpenHelperFactory() + }, + ) } addSingletonFactory { diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/DbOpenCallback.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/DbOpenCallback.kt deleted file mode 100644 index 14905d8760..0000000000 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/DbOpenCallback.kt +++ /dev/null @@ -1,34 +0,0 @@ -package eu.kanade.tachiyomi.data.database - -import androidx.sqlite.db.SupportSQLiteDatabase -import androidx.sqlite.db.SupportSQLiteOpenHelper -import com.squareup.sqldelight.android.AndroidSqliteDriver -import eu.kanade.tachiyomi.Database -import logcat.logcat - -class DbOpenCallback : SupportSQLiteOpenHelper.Callback(Database.Schema.version) { - - companion object { - const val DATABASE_FILENAME = "tachiyomi.db" - } - - override fun onCreate(db: SupportSQLiteDatabase) { - logcat { "Creating new database" } - Database.Schema.create(AndroidSqliteDriver(database = db, cacheSize = 1)) - } - - override fun onUpgrade(db: SupportSQLiteDatabase, oldVersion: Int, newVersion: Int) { - if (oldVersion < newVersion) { - logcat { "Upgrading database from $oldVersion to $newVersion" } - Database.Schema.migrate( - driver = AndroidSqliteDriver(database = db, cacheSize = 1), - oldVersion = oldVersion, - newVersion = newVersion, - ) - } - } - - override fun onConfigure(db: SupportSQLiteDatabase) { - db.setForeignKeyConstraintsEnabled(true) - } -}