mirror of
https://github.com/Suwayomi/TachideskJUI.git
synced 2025-12-10 06:42:05 +01:00
Implement migrations
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import Config.migrationCode
|
||||
import Config.serverCode
|
||||
import Config.tachideskVersion
|
||||
import org.gradle.jvm.tasks.Jar
|
||||
@@ -228,7 +229,9 @@ buildConfig {
|
||||
|
||||
buildConfigField("String", "NAME", project.name.wrap())
|
||||
buildConfigField("String", "VERSION", project.version.toString().wrap())
|
||||
buildConfigField("int", "MIGRATION_CODE", migrationCode.toString())
|
||||
|
||||
// Tachidesk
|
||||
buildConfigField("boolean", "DEBUG", project.hasProperty("debugApp").toString())
|
||||
buildConfigField("String", "TACHIDESK_SP_VERSION", tachideskVersion.wrap())
|
||||
buildConfigField("int", "SERVER_CODE", serverCode.toString())
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import org.gradle.api.JavaVersion
|
||||
|
||||
object Config {
|
||||
const val migrationCode = 1
|
||||
|
||||
// Tachidesk
|
||||
const val tachideskVersion = "v0.6.0"
|
||||
// Match this to the Tachidesk-Server commit count
|
||||
const val serverCode = 1049
|
||||
|
||||
@@ -12,6 +12,8 @@ import ca.gosyer.data.download.DownloadService
|
||||
import ca.gosyer.data.extension.ExtensionPreferences
|
||||
import ca.gosyer.data.library.LibraryPreferences
|
||||
import ca.gosyer.data.library.LibraryUpdateService
|
||||
import ca.gosyer.data.migration.MigrationPreferences
|
||||
import ca.gosyer.data.migration.Migrations
|
||||
import ca.gosyer.data.reader.ReaderPreferences
|
||||
import ca.gosyer.data.server.Http
|
||||
import ca.gosyer.data.server.HttpProvider
|
||||
@@ -65,6 +67,10 @@ val DataModule = module {
|
||||
.toProviderInstance { UiPreferences(preferenceFactory.create("ui")) }
|
||||
.providesSingleton()
|
||||
|
||||
bind<MigrationPreferences>()
|
||||
.toProviderInstance { MigrationPreferences(preferenceFactory.create("migration")) }
|
||||
.providesSingleton()
|
||||
|
||||
bind<Http>()
|
||||
.toProvider(HttpProvider::class)
|
||||
.providesSingleton()
|
||||
@@ -104,4 +110,8 @@ val DataModule = module {
|
||||
bind<LibraryUpdateService>()
|
||||
.toClass<LibraryUpdateService>()
|
||||
.singleton()
|
||||
|
||||
bind<Migrations>()
|
||||
.toClass<Migrations>()
|
||||
.singleton()
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
package ca.gosyer.data.migration
|
||||
|
||||
import ca.gosyer.common.prefs.Preference
|
||||
import ca.gosyer.common.prefs.PreferenceStore
|
||||
|
||||
class MigrationPreferences(private val preferenceStore: PreferenceStore) {
|
||||
fun version(): Preference<Int> {
|
||||
return preferenceStore.getInt("version", 0)
|
||||
}
|
||||
}
|
||||
27
src/main/kotlin/ca/gosyer/data/migration/Migrations.kt
Normal file
27
src/main/kotlin/ca/gosyer/data/migration/Migrations.kt
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
package ca.gosyer.data.migration
|
||||
|
||||
import ca.gosyer.build.BuildConfig
|
||||
import ca.gosyer.data.reader.ReaderPreferences
|
||||
import javax.inject.Inject
|
||||
|
||||
class Migrations @Inject constructor(
|
||||
private val migrationPreferences: MigrationPreferences,
|
||||
private val readerPreferences: ReaderPreferences
|
||||
) {
|
||||
|
||||
fun runMigrations() {
|
||||
val code = migrationPreferences.version().get()
|
||||
if (code <= 0) {
|
||||
readerPreferences.modes().get().forEach {
|
||||
readerPreferences.getMode(it).direction().delete()
|
||||
}
|
||||
migrationPreferences.version().set(BuildConfig.MIGRATION_CODE)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,7 @@ import androidx.compose.ui.window.rememberWindowState
|
||||
import ca.gosyer.build.BuildConfig
|
||||
import ca.gosyer.core.logging.initializeLogger
|
||||
import ca.gosyer.data.DataModule
|
||||
import ca.gosyer.data.migration.Migrations
|
||||
import ca.gosyer.data.server.ServerService
|
||||
import ca.gosyer.data.server.ServerService.ServerResult
|
||||
import ca.gosyer.data.translation.XmlResourceBundle
|
||||
@@ -82,6 +83,8 @@ suspend fun main() {
|
||||
DataModule
|
||||
)
|
||||
|
||||
scope.getInstance<Migrations>().runMigrations()
|
||||
|
||||
val serverService = scope.getInstance<ServerService>()
|
||||
val uiPreferences = scope.getInstance<UiPreferences>()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user