mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-22 09:11:52 +01:00
Remove SQLiteOpenHelper as database is migrated to SQLDelight (#7448)
This commit is contained in:
parent
17951cfd68
commit
eb2a904b61
@ -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<SupportSQLiteOpenHelper> {
|
||||
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<SqlDriver> {
|
||||
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 {
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user