mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-13 22:12:49 +01:00
Remove unnecessary migrations
This commit is contained in:
parent
1aa75f22d0
commit
e51013d2a4
@ -1,34 +1,10 @@
|
|||||||
package eu.kanade.tachiyomi
|
package eu.kanade.tachiyomi
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import androidx.core.content.edit
|
|
||||||
import androidx.preference.PreferenceManager
|
|
||||||
import eu.kanade.domain.base.BasePreferences
|
|
||||||
import eu.kanade.domain.source.service.SourcePreferences
|
|
||||||
import eu.kanade.domain.ui.UiPreferences
|
|
||||||
import eu.kanade.tachiyomi.core.security.SecurityPreferences
|
|
||||||
import eu.kanade.tachiyomi.data.backup.create.BackupCreateJob
|
import eu.kanade.tachiyomi.data.backup.create.BackupCreateJob
|
||||||
import eu.kanade.tachiyomi.data.library.LibraryUpdateJob
|
import eu.kanade.tachiyomi.data.library.LibraryUpdateJob
|
||||||
import eu.kanade.tachiyomi.data.track.TrackerManager
|
|
||||||
import eu.kanade.tachiyomi.network.NetworkPreferences
|
|
||||||
import eu.kanade.tachiyomi.network.PREF_DOH_CLOUDFLARE
|
|
||||||
import eu.kanade.tachiyomi.ui.reader.setting.ReaderOrientation
|
|
||||||
import eu.kanade.tachiyomi.ui.reader.setting.ReaderPreferences
|
|
||||||
import eu.kanade.tachiyomi.util.system.DeviceUtil
|
|
||||||
import eu.kanade.tachiyomi.util.system.toast
|
|
||||||
import eu.kanade.tachiyomi.util.system.workManager
|
|
||||||
import tachiyomi.core.preference.Preference
|
import tachiyomi.core.preference.Preference
|
||||||
import tachiyomi.core.preference.PreferenceStore
|
import tachiyomi.core.preference.PreferenceStore
|
||||||
import tachiyomi.core.preference.TriState
|
|
||||||
import tachiyomi.core.preference.getAndSet
|
|
||||||
import tachiyomi.core.preference.getEnum
|
|
||||||
import tachiyomi.core.preference.minusAssign
|
|
||||||
import tachiyomi.core.preference.plusAssign
|
|
||||||
import tachiyomi.domain.backup.service.BackupPreferences
|
|
||||||
import tachiyomi.domain.library.service.LibraryPreferences
|
|
||||||
import tachiyomi.domain.library.service.LibraryPreferences.Companion.MANGA_NON_COMPLETED
|
|
||||||
import tachiyomi.i18n.MR
|
|
||||||
import java.io.File
|
|
||||||
|
|
||||||
object Migrations {
|
object Migrations {
|
||||||
|
|
||||||
@ -37,18 +13,10 @@ object Migrations {
|
|||||||
*
|
*
|
||||||
* @return true if a migration is performed, false otherwise.
|
* @return true if a migration is performed, false otherwise.
|
||||||
*/
|
*/
|
||||||
|
@Suppress("SameReturnValue")
|
||||||
fun upgrade(
|
fun upgrade(
|
||||||
context: Context,
|
context: Context,
|
||||||
preferenceStore: PreferenceStore,
|
preferenceStore: PreferenceStore,
|
||||||
basePreferences: BasePreferences,
|
|
||||||
uiPreferences: UiPreferences,
|
|
||||||
networkPreferences: NetworkPreferences,
|
|
||||||
sourcePreferences: SourcePreferences,
|
|
||||||
securityPreferences: SecurityPreferences,
|
|
||||||
libraryPreferences: LibraryPreferences,
|
|
||||||
readerPreferences: ReaderPreferences,
|
|
||||||
backupPreferences: BackupPreferences,
|
|
||||||
trackerManager: TrackerManager,
|
|
||||||
): Boolean {
|
): Boolean {
|
||||||
val lastVersionCode = preferenceStore.getInt(Preference.appStateKey("last_version_code"), 0)
|
val lastVersionCode = preferenceStore.getInt(Preference.appStateKey("last_version_code"), 0)
|
||||||
val oldVersion = lastVersionCode.get()
|
val oldVersion = lastVersionCode.get()
|
||||||
@ -63,399 +31,8 @@ object Migrations {
|
|||||||
if (oldVersion == 0) {
|
if (oldVersion == 0) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
|
|
||||||
|
|
||||||
if (oldVersion < 15) {
|
|
||||||
// Delete internal chapter cache dir.
|
|
||||||
File(context.cacheDir, "chapter_disk_cache").deleteRecursively()
|
|
||||||
}
|
|
||||||
if (oldVersion < 19) {
|
|
||||||
// Move covers to external files dir.
|
|
||||||
val oldDir = File(context.externalCacheDir, "cover_disk_cache")
|
|
||||||
if (oldDir.exists()) {
|
|
||||||
val destDir = context.getExternalFilesDir("covers")
|
|
||||||
if (destDir != null) {
|
|
||||||
oldDir.listFiles()?.forEach {
|
|
||||||
it.renameTo(File(destDir, it.name))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (oldVersion < 26) {
|
|
||||||
// Delete external chapter cache dir.
|
|
||||||
val extCache = context.externalCacheDir
|
|
||||||
if (extCache != null) {
|
|
||||||
val chapterCache = File(extCache, "chapter_disk_cache")
|
|
||||||
if (chapterCache.exists()) {
|
|
||||||
chapterCache.deleteRecursively()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (oldVersion < 44) {
|
|
||||||
// Reset sorting preference if using removed sort by source
|
|
||||||
val oldSortingMode = prefs.getInt(libraryPreferences.sortingMode().key(), 0)
|
|
||||||
|
|
||||||
if (oldSortingMode == 5) { // SOURCE = 5
|
|
||||||
prefs.edit {
|
|
||||||
putInt(libraryPreferences.sortingMode().key(), 0) // ALPHABETICAL = 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (oldVersion < 52) {
|
|
||||||
// Migrate library filters to tri-state versions
|
|
||||||
fun convertBooleanPrefToTriState(key: String): Int {
|
|
||||||
val oldPrefValue = prefs.getBoolean(key, false)
|
|
||||||
return if (oldPrefValue) {
|
|
||||||
1
|
|
||||||
} else {
|
|
||||||
0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
prefs.edit {
|
|
||||||
putInt(
|
|
||||||
libraryPreferences.filterDownloaded().key(),
|
|
||||||
convertBooleanPrefToTriState("pref_filter_downloaded_key"),
|
|
||||||
)
|
|
||||||
remove("pref_filter_downloaded_key")
|
|
||||||
|
|
||||||
putInt(
|
|
||||||
libraryPreferences.filterUnread().key(),
|
|
||||||
convertBooleanPrefToTriState("pref_filter_unread_key"),
|
|
||||||
)
|
|
||||||
remove("pref_filter_unread_key")
|
|
||||||
|
|
||||||
putInt(
|
|
||||||
libraryPreferences.filterCompleted().key(),
|
|
||||||
convertBooleanPrefToTriState("pref_filter_completed_key"),
|
|
||||||
)
|
|
||||||
remove("pref_filter_completed_key")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (oldVersion < 54) {
|
|
||||||
// Force MAL log out due to login flow change
|
|
||||||
// v52: switched from scraping to WebView
|
|
||||||
// v53: switched from WebView to OAuth
|
|
||||||
if (trackerManager.myAnimeList.isLoggedIn) {
|
|
||||||
trackerManager.myAnimeList.logout()
|
|
||||||
context.toast(MR.strings.myanimelist_relogin)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (oldVersion < 57) {
|
|
||||||
// Migrate DNS over HTTPS setting
|
|
||||||
val wasDohEnabled = prefs.getBoolean("enable_doh", false)
|
|
||||||
if (wasDohEnabled) {
|
|
||||||
prefs.edit {
|
|
||||||
putInt(networkPreferences.dohProvider().key(), PREF_DOH_CLOUDFLARE)
|
|
||||||
remove("enable_doh")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (oldVersion < 59) {
|
|
||||||
// Reset rotation to Free after replacing Lock
|
|
||||||
if (prefs.contains("pref_rotation_type_key")) {
|
|
||||||
prefs.edit {
|
|
||||||
putInt("pref_rotation_type_key", 1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (oldVersion < 60) {
|
|
||||||
// Migrate Rotation and Viewer values to default values for viewer_flags
|
|
||||||
val newOrientation = when (prefs.getInt("pref_rotation_type_key", 1)) {
|
|
||||||
1 -> ReaderOrientation.FREE.flagValue
|
|
||||||
2 -> ReaderOrientation.PORTRAIT.flagValue
|
|
||||||
3 -> ReaderOrientation.LANDSCAPE.flagValue
|
|
||||||
4 -> ReaderOrientation.LOCKED_PORTRAIT.flagValue
|
|
||||||
5 -> ReaderOrientation.LOCKED_LANDSCAPE.flagValue
|
|
||||||
else -> ReaderOrientation.FREE.flagValue
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reading mode flag and prefValue is the same value
|
|
||||||
val newReadingMode = prefs.getInt("pref_default_viewer_key", 1)
|
|
||||||
|
|
||||||
prefs.edit {
|
|
||||||
putInt("pref_default_orientation_type_key", newOrientation)
|
|
||||||
remove("pref_rotation_type_key")
|
|
||||||
putInt("pref_default_reading_mode_key", newReadingMode)
|
|
||||||
remove("pref_default_viewer_key")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (oldVersion < 61) {
|
|
||||||
// Handle removed every 1 or 2 hour library updates
|
|
||||||
val updateInterval = libraryPreferences.autoUpdateInterval().get()
|
|
||||||
if (updateInterval == 1 || updateInterval == 2) {
|
|
||||||
libraryPreferences.autoUpdateInterval().set(3)
|
|
||||||
LibraryUpdateJob.setupTask(context, 3)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (oldVersion < 64) {
|
|
||||||
val oldSortingMode = prefs.getInt(libraryPreferences.sortingMode().key(), 0)
|
|
||||||
val oldSortingDirection = prefs.getBoolean("library_sorting_ascending", true)
|
|
||||||
|
|
||||||
val newSortingMode = when (oldSortingMode) {
|
|
||||||
0 -> "ALPHABETICAL"
|
|
||||||
1 -> "LAST_READ"
|
|
||||||
2 -> "LAST_CHECKED"
|
|
||||||
3 -> "UNREAD"
|
|
||||||
4 -> "TOTAL_CHAPTERS"
|
|
||||||
6 -> "LATEST_CHAPTER"
|
|
||||||
8 -> "DATE_FETCHED"
|
|
||||||
7 -> "DATE_ADDED"
|
|
||||||
else -> "ALPHABETICAL"
|
|
||||||
}
|
|
||||||
|
|
||||||
val newSortingDirection = when (oldSortingDirection) {
|
|
||||||
true -> "ASCENDING"
|
|
||||||
else -> "DESCENDING"
|
|
||||||
}
|
|
||||||
|
|
||||||
prefs.edit(commit = true) {
|
|
||||||
remove(libraryPreferences.sortingMode().key())
|
|
||||||
remove("library_sorting_ascending")
|
|
||||||
}
|
|
||||||
|
|
||||||
prefs.edit {
|
|
||||||
putString(libraryPreferences.sortingMode().key(), newSortingMode)
|
|
||||||
putString("library_sorting_ascending", newSortingDirection)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (oldVersion < 70) {
|
|
||||||
if (sourcePreferences.enabledLanguages().isSet()) {
|
|
||||||
sourcePreferences.enabledLanguages() += "all"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (oldVersion < 71) {
|
|
||||||
// Handle removed every 3, 4, 6, and 8 hour library updates
|
|
||||||
val updateInterval = libraryPreferences.autoUpdateInterval().get()
|
|
||||||
if (updateInterval in listOf(3, 4, 6, 8)) {
|
|
||||||
libraryPreferences.autoUpdateInterval().set(12)
|
|
||||||
LibraryUpdateJob.setupTask(context, 12)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (oldVersion < 72) {
|
|
||||||
val oldUpdateOngoingOnly = prefs.getBoolean("pref_update_only_non_completed_key", true)
|
|
||||||
if (!oldUpdateOngoingOnly) {
|
|
||||||
libraryPreferences.autoUpdateMangaRestrictions() -= MANGA_NON_COMPLETED
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (oldVersion < 75) {
|
|
||||||
val oldSecureScreen = prefs.getBoolean("secure_screen", false)
|
|
||||||
if (oldSecureScreen) {
|
|
||||||
securityPreferences.secureScreen().set(SecurityPreferences.SecureScreenMode.ALWAYS)
|
|
||||||
}
|
|
||||||
if (
|
|
||||||
DeviceUtil.isMiui &&
|
|
||||||
basePreferences.extensionInstaller().get() == BasePreferences.ExtensionInstaller.PACKAGEINSTALLER
|
|
||||||
) {
|
|
||||||
basePreferences.extensionInstaller().set(BasePreferences.ExtensionInstaller.LEGACY)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (oldVersion < 77) {
|
|
||||||
val oldReaderTap = prefs.getBoolean("reader_tap", false)
|
|
||||||
if (!oldReaderTap) {
|
|
||||||
readerPreferences.navigationModePager().set(5)
|
|
||||||
readerPreferences.navigationModeWebtoon().set(5)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (oldVersion < 81) {
|
|
||||||
// Handle renamed enum values
|
|
||||||
prefs.edit {
|
|
||||||
val newSortingMode = when (
|
|
||||||
val oldSortingMode = prefs.getString(
|
|
||||||
libraryPreferences.sortingMode().key(),
|
|
||||||
"ALPHABETICAL",
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
"LAST_CHECKED" -> "LAST_MANGA_UPDATE"
|
|
||||||
"UNREAD" -> "UNREAD_COUNT"
|
|
||||||
"DATE_FETCHED" -> "CHAPTER_FETCH_DATE"
|
|
||||||
else -> oldSortingMode
|
|
||||||
}
|
|
||||||
putString(libraryPreferences.sortingMode().key(), newSortingMode)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (oldVersion < 82) {
|
|
||||||
prefs.edit {
|
|
||||||
val sort = prefs.getString(libraryPreferences.sortingMode().key(), null) ?: return@edit
|
|
||||||
val direction = prefs.getString("library_sorting_ascending", "ASCENDING")!!
|
|
||||||
putString(libraryPreferences.sortingMode().key(), "$sort,$direction")
|
|
||||||
remove("library_sorting_ascending")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (oldVersion < 84) {
|
|
||||||
if (backupPreferences.backupInterval().get() == 0) {
|
|
||||||
backupPreferences.backupInterval().set(12)
|
|
||||||
BackupCreateJob.setupTask(context)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (oldVersion < 85) {
|
|
||||||
val preferences = listOf(
|
|
||||||
libraryPreferences.filterChapterByRead(),
|
|
||||||
libraryPreferences.filterChapterByDownloaded(),
|
|
||||||
libraryPreferences.filterChapterByBookmarked(),
|
|
||||||
libraryPreferences.sortChapterBySourceOrNumber(),
|
|
||||||
libraryPreferences.displayChapterByNameOrNumber(),
|
|
||||||
libraryPreferences.sortChapterByAscendingOrDescending(),
|
|
||||||
)
|
|
||||||
|
|
||||||
prefs.edit {
|
|
||||||
preferences.forEach { preference ->
|
|
||||||
val key = preference.key()
|
|
||||||
val value = prefs.getInt(key, Int.MIN_VALUE)
|
|
||||||
if (value == Int.MIN_VALUE) return@forEach
|
|
||||||
remove(key)
|
|
||||||
putLong(key, value.toLong())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (oldVersion < 86) {
|
|
||||||
if (uiPreferences.themeMode().isSet()) {
|
|
||||||
prefs.edit {
|
|
||||||
val themeMode = prefs.getString(uiPreferences.themeMode().key(), null) ?: return@edit
|
|
||||||
putString(uiPreferences.themeMode().key(), themeMode.uppercase())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (oldVersion < 92) {
|
|
||||||
val trackingQueuePref = context.getSharedPreferences("tracking_queue", Context.MODE_PRIVATE)
|
|
||||||
trackingQueuePref.all.forEach {
|
|
||||||
val (_, lastChapterRead) = it.value.toString().split(":")
|
|
||||||
trackingQueuePref.edit {
|
|
||||||
remove(it.key)
|
|
||||||
putFloat(it.key, lastChapterRead.toFloat())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (oldVersion < 96) {
|
|
||||||
LibraryUpdateJob.cancelAllWorks(context)
|
|
||||||
LibraryUpdateJob.setupTask(context)
|
|
||||||
}
|
|
||||||
if (oldVersion < 97) {
|
|
||||||
// Removed background jobs
|
|
||||||
context.workManager.cancelAllWorkByTag("UpdateChecker")
|
|
||||||
context.workManager.cancelAllWorkByTag("ExtensionUpdate")
|
|
||||||
prefs.edit {
|
|
||||||
remove("automatic_ext_updates")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (oldVersion < 99) {
|
|
||||||
val prefKeys = listOf(
|
|
||||||
"pref_filter_library_downloaded",
|
|
||||||
"pref_filter_library_unread",
|
|
||||||
"pref_filter_library_started",
|
|
||||||
"pref_filter_library_bookmarked",
|
|
||||||
"pref_filter_library_completed",
|
|
||||||
) + trackerManager.trackers.map { "pref_filter_library_tracked_${it.id}" }
|
|
||||||
|
|
||||||
prefKeys.forEach { key ->
|
|
||||||
val pref = preferenceStore.getInt(key, 0)
|
|
||||||
prefs.edit {
|
|
||||||
remove(key)
|
|
||||||
|
|
||||||
val newValue = when (pref.get()) {
|
|
||||||
1 -> TriState.ENABLED_IS
|
|
||||||
2 -> TriState.ENABLED_NOT
|
|
||||||
else -> TriState.DISABLED
|
|
||||||
}
|
|
||||||
|
|
||||||
preferenceStore.getEnum("${key}_v2", TriState.DISABLED).set(newValue)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (oldVersion < 105) {
|
|
||||||
val pref = libraryPreferences.autoUpdateDeviceRestrictions()
|
|
||||||
if (pref.isSet() && "battery_not_low" in pref.get()) {
|
|
||||||
pref.getAndSet { it - "battery_not_low" }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (oldVersion < 106) {
|
|
||||||
val pref = preferenceStore.getInt("relative_time", 7)
|
|
||||||
if (pref.get() == 0) {
|
|
||||||
uiPreferences.relativeTime().set(false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (oldVersion < 113) {
|
|
||||||
val prefsToReplace = listOf(
|
|
||||||
"pref_download_only",
|
|
||||||
"incognito_mode",
|
|
||||||
"last_catalogue_source",
|
|
||||||
"trusted_signatures",
|
|
||||||
"last_app_closed",
|
|
||||||
"library_update_last_timestamp",
|
|
||||||
"library_unseen_updates_count",
|
|
||||||
"last_used_category",
|
|
||||||
"last_app_check",
|
|
||||||
"last_ext_check",
|
|
||||||
"last_version_code",
|
|
||||||
"storage_dir",
|
|
||||||
)
|
|
||||||
replacePreferences(
|
|
||||||
preferenceStore = preferenceStore,
|
|
||||||
filterPredicate = { it.key in prefsToReplace },
|
|
||||||
newKey = { Preference.appStateKey(it) },
|
|
||||||
)
|
|
||||||
|
|
||||||
// Deleting old download cache index files, but might as well clear it all out
|
|
||||||
context.cacheDir.deleteRecursively()
|
|
||||||
}
|
|
||||||
if (oldVersion < 114) {
|
|
||||||
sourcePreferences.extensionRepos().getAndSet {
|
|
||||||
it.map { repo -> "https://raw.githubusercontent.com/$repo/repo" }.toSet()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (oldVersion < 116) {
|
|
||||||
replacePreferences(
|
|
||||||
preferenceStore = preferenceStore,
|
|
||||||
filterPredicate = { it.key.startsWith("pref_mangasync_") || it.key.startsWith("track_token_") },
|
|
||||||
newKey = { Preference.privateKey(it) },
|
|
||||||
)
|
|
||||||
}
|
|
||||||
if (oldVersion < 117) {
|
|
||||||
prefs.edit {
|
|
||||||
remove(Preference.appStateKey("trusted_signatures"))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
|
||||||
private fun replacePreferences(
|
|
||||||
preferenceStore: PreferenceStore,
|
|
||||||
filterPredicate: (Map.Entry<String, Any?>) -> Boolean,
|
|
||||||
newKey: (String) -> String,
|
|
||||||
) {
|
|
||||||
preferenceStore.getAll()
|
|
||||||
.filter(filterPredicate)
|
|
||||||
.forEach { (key, value) ->
|
|
||||||
when (value) {
|
|
||||||
is Int -> {
|
|
||||||
preferenceStore.getInt(newKey(key)).set(value)
|
|
||||||
preferenceStore.getInt(key).delete()
|
|
||||||
}
|
|
||||||
is Long -> {
|
|
||||||
preferenceStore.getLong(newKey(key)).set(value)
|
|
||||||
preferenceStore.getLong(key).delete()
|
|
||||||
}
|
|
||||||
is Float -> {
|
|
||||||
preferenceStore.getFloat(newKey(key)).set(value)
|
|
||||||
preferenceStore.getFloat(key).delete()
|
|
||||||
}
|
|
||||||
is String -> {
|
|
||||||
preferenceStore.getString(newKey(key)).set(value)
|
|
||||||
preferenceStore.getString(key).delete()
|
|
||||||
}
|
|
||||||
is Boolean -> {
|
|
||||||
preferenceStore.getBoolean(newKey(key)).set(value)
|
|
||||||
preferenceStore.getBoolean(key).delete()
|
|
||||||
}
|
|
||||||
is Set<*> -> (value as? Set<String>)?.let {
|
|
||||||
preferenceStore.getStringSet(newKey(key)).set(value)
|
|
||||||
preferenceStore.getStringSet(key).delete()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -133,16 +133,7 @@ class MainActivity : BaseActivity() {
|
|||||||
val didMigration = if (isLaunch) {
|
val didMigration = if (isLaunch) {
|
||||||
Migrations.upgrade(
|
Migrations.upgrade(
|
||||||
context = applicationContext,
|
context = applicationContext,
|
||||||
basePreferences = preferences,
|
|
||||||
uiPreferences = uiPreferences,
|
|
||||||
preferenceStore = Injekt.get(),
|
preferenceStore = Injekt.get(),
|
||||||
networkPreferences = Injekt.get(),
|
|
||||||
sourcePreferences = sourcePreferences,
|
|
||||||
securityPreferences = Injekt.get(),
|
|
||||||
libraryPreferences = libraryPreferences,
|
|
||||||
readerPreferences = Injekt.get(),
|
|
||||||
backupPreferences = Injekt.get(),
|
|
||||||
trackerManager = Injekt.get(),
|
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
ALTER TABLE chapters
|
|
||||||
ADD COLUMN source_order INTEGER DEFAULT 0;
|
|
||||||
|
|
||||||
UPDATE mangas
|
|
||||||
SET thumbnail_url = replace(thumbnail_url, '93.174.95.110', 'kissmanga.com')
|
|
||||||
WHERE source = 4;
|
|
@ -1,11 +0,0 @@
|
|||||||
ALTER TABLE mangas
|
|
||||||
ADD COLUMN date_added INTEGER NOT NULL DEFAULT 0;
|
|
||||||
|
|
||||||
UPDATE mangas
|
|
||||||
SET date_added = (
|
|
||||||
SELECT MIN(date_fetch)
|
|
||||||
FROM mangas M
|
|
||||||
INNER JOIN chapters C
|
|
||||||
ON M._id = C.manga_id
|
|
||||||
GROUP BY M._id
|
|
||||||
);
|
|
@ -1,2 +0,0 @@
|
|||||||
ALTER TABLE mangas
|
|
||||||
ADD COLUMN next_update INTEGER DEFAULT 0;
|
|
@ -1,27 +0,0 @@
|
|||||||
ALTER TABLE manga_sync
|
|
||||||
RENAME TO manga_sync_tmp;
|
|
||||||
|
|
||||||
CREATE TABLE manga_sync(
|
|
||||||
_id INTEGER NOT NULL PRIMARY KEY,
|
|
||||||
manga_id INTEGER NOT NULL,
|
|
||||||
sync_id INTEGER NOT NULL,
|
|
||||||
remote_id INTEGER NOT NULL,
|
|
||||||
library_id INTEGER,
|
|
||||||
title TEXT NOT NULL,
|
|
||||||
last_chapter_read REAL NOT NULL,
|
|
||||||
total_chapters INTEGER NOT NULL,
|
|
||||||
status INTEGER NOT NULL,
|
|
||||||
score REAL AS Float NOT NULL,
|
|
||||||
remote_url TEXT NOT NULL,
|
|
||||||
start_date INTEGER AS Long NOT NULL,
|
|
||||||
finish_date INTEGER AS Long NOT NULL,
|
|
||||||
UNIQUE (manga_id, sync_id) ON CONFLICT REPLACE,
|
|
||||||
FOREIGN KEY(manga_id) REFERENCES mangas (_id)
|
|
||||||
ON DELETE CASCADE
|
|
||||||
);
|
|
||||||
|
|
||||||
INSERT INTO manga_sync(_id, manga_id, sync_id, remote_id, library_id, title, last_chapter_read, total_chapters, status, score, remote_url, start_date, finish_date)
|
|
||||||
SELECT _id, manga_id, sync_id, remote_id, library_id, title, last_chapter_read, total_chapters, status, score, remote_url, start_date, finish_date
|
|
||||||
FROM manga_sync_tmp;
|
|
||||||
|
|
||||||
DROP TABLE manga_sync_tmp;
|
|
@ -1,3 +0,0 @@
|
|||||||
UPDATE chapters
|
|
||||||
SET date_upload = date_fetch
|
|
||||||
WHERE date_upload = 0;
|
|
@ -1,149 +0,0 @@
|
|||||||
DROP INDEX IF EXISTS chapters_manga_id_index;
|
|
||||||
DROP INDEX IF EXISTS chapters_unread_by_manga_index;
|
|
||||||
DROP INDEX IF EXISTS history_history_chapter_id_index;
|
|
||||||
DROP INDEX IF EXISTS library_favorite_index;
|
|
||||||
DROP INDEX IF EXISTS mangas_url_index;
|
|
||||||
|
|
||||||
ALTER TABLE mangas RENAME TO manga_temp;
|
|
||||||
CREATE TABLE mangas(
|
|
||||||
_id INTEGER NOT NULL PRIMARY KEY,
|
|
||||||
source INTEGER NOT NULL,
|
|
||||||
url TEXT NOT NULL,
|
|
||||||
artist TEXT,
|
|
||||||
author TEXT,
|
|
||||||
description TEXT,
|
|
||||||
genre TEXT,
|
|
||||||
title TEXT NOT NULL,
|
|
||||||
status INTEGER NOT NULL,
|
|
||||||
thumbnail_url TEXT,
|
|
||||||
favorite INTEGER NOT NULL,
|
|
||||||
last_update INTEGER AS Long,
|
|
||||||
next_update INTEGER AS Long,
|
|
||||||
initialized INTEGER AS Boolean NOT NULL,
|
|
||||||
viewer INTEGER NOT NULL,
|
|
||||||
chapter_flags INTEGER NOT NULL,
|
|
||||||
cover_last_modified INTEGER AS Long NOT NULL,
|
|
||||||
date_added INTEGER AS Long NOT NULL
|
|
||||||
);
|
|
||||||
INSERT INTO mangas
|
|
||||||
SELECT _id,source,url,artist,author,description,genre,title,status,thumbnail_url,favorite,last_update,next_update,initialized,viewer,chapter_flags,cover_last_modified,date_added
|
|
||||||
FROM manga_temp;
|
|
||||||
|
|
||||||
ALTER TABLE categories RENAME TO categories_temp;
|
|
||||||
CREATE TABLE categories(
|
|
||||||
_id INTEGER NOT NULL PRIMARY KEY,
|
|
||||||
name TEXT NOT NULL,
|
|
||||||
sort INTEGER NOT NULL,
|
|
||||||
flags INTEGER NOT NULL
|
|
||||||
);
|
|
||||||
INSERT INTO categories
|
|
||||||
SELECT _id,name,sort,flags
|
|
||||||
FROM categories_temp;
|
|
||||||
|
|
||||||
ALTER TABLE chapters RENAME TO chapters_temp;
|
|
||||||
CREATE TABLE chapters(
|
|
||||||
_id INTEGER NOT NULL PRIMARY KEY,
|
|
||||||
manga_id INTEGER NOT NULL,
|
|
||||||
url TEXT NOT NULL,
|
|
||||||
name TEXT NOT NULL,
|
|
||||||
scanlator TEXT,
|
|
||||||
read INTEGER AS Boolean NOT NULL,
|
|
||||||
bookmark INTEGER AS Boolean NOT NULL,
|
|
||||||
last_page_read INTEGER NOT NULL,
|
|
||||||
chapter_number REAL AS Float NOT NULL,
|
|
||||||
source_order INTEGER NOT NULL,
|
|
||||||
date_fetch INTEGER AS Long NOT NULL,
|
|
||||||
date_upload INTEGER AS Long NOT NULL,
|
|
||||||
FOREIGN KEY(manga_id) REFERENCES mangas (_id)
|
|
||||||
ON DELETE CASCADE
|
|
||||||
);
|
|
||||||
INSERT INTO chapters
|
|
||||||
SELECT _id,manga_id,url,name,scanlator,read,bookmark,last_page_read,chapter_number,source_order,date_fetch,date_upload
|
|
||||||
FROM chapters_temp;
|
|
||||||
|
|
||||||
ALTER TABLE history RENAME TO history_temp;
|
|
||||||
CREATE TABLE history(
|
|
||||||
history_id INTEGER NOT NULL PRIMARY KEY,
|
|
||||||
history_chapter_id INTEGER NOT NULL UNIQUE,
|
|
||||||
history_last_read INTEGER AS Long,
|
|
||||||
history_time_read INTEGER AS Long,
|
|
||||||
FOREIGN KEY(history_chapter_id) REFERENCES chapters (_id)
|
|
||||||
ON DELETE CASCADE
|
|
||||||
);
|
|
||||||
INSERT INTO history
|
|
||||||
SELECT history_id, history_chapter_id, history_last_read, history_time_read
|
|
||||||
FROM history_temp;
|
|
||||||
|
|
||||||
ALTER TABLE mangas_categories RENAME TO mangas_categories_temp;
|
|
||||||
CREATE TABLE mangas_categories(
|
|
||||||
_id INTEGER NOT NULL PRIMARY KEY,
|
|
||||||
manga_id INTEGER NOT NULL,
|
|
||||||
category_id INTEGER NOT NULL,
|
|
||||||
FOREIGN KEY(category_id) REFERENCES categories (_id)
|
|
||||||
ON DELETE CASCADE,
|
|
||||||
FOREIGN KEY(manga_id) REFERENCES mangas (_id)
|
|
||||||
ON DELETE CASCADE
|
|
||||||
);
|
|
||||||
INSERT INTO mangas_categories
|
|
||||||
SELECT _id, manga_id, category_id
|
|
||||||
FROM mangas_categories_temp;
|
|
||||||
|
|
||||||
ALTER TABLE manga_sync RENAME TO manga_sync_temp;
|
|
||||||
CREATE TABLE manga_sync(
|
|
||||||
_id INTEGER NOT NULL PRIMARY KEY,
|
|
||||||
manga_id INTEGER NOT NULL,
|
|
||||||
sync_id INTEGER NOT NULL,
|
|
||||||
remote_id INTEGER NOT NULL,
|
|
||||||
library_id INTEGER,
|
|
||||||
title TEXT NOT NULL,
|
|
||||||
last_chapter_read REAL NOT NULL,
|
|
||||||
total_chapters INTEGER NOT NULL,
|
|
||||||
status INTEGER NOT NULL,
|
|
||||||
score REAL AS Float NOT NULL,
|
|
||||||
remote_url TEXT NOT NULL,
|
|
||||||
start_date INTEGER AS Long NOT NULL,
|
|
||||||
finish_date INTEGER AS Long NOT NULL,
|
|
||||||
UNIQUE (manga_id, sync_id) ON CONFLICT REPLACE,
|
|
||||||
FOREIGN KEY(manga_id) REFERENCES mangas (_id)
|
|
||||||
ON DELETE CASCADE
|
|
||||||
);
|
|
||||||
INSERT INTO manga_sync
|
|
||||||
SELECT _id, manga_id, sync_id, remote_id, library_id, title, last_chapter_read, total_chapters, status, score, remote_url, start_date, finish_date
|
|
||||||
FROM manga_sync_temp;
|
|
||||||
|
|
||||||
CREATE INDEX chapters_manga_id_index ON chapters(manga_id);
|
|
||||||
CREATE INDEX chapters_unread_by_manga_index ON chapters(manga_id, read) WHERE read = 0;
|
|
||||||
CREATE INDEX history_history_chapter_id_index ON history(history_chapter_id);
|
|
||||||
CREATE INDEX library_favorite_index ON mangas(favorite) WHERE favorite = 1;
|
|
||||||
CREATE INDEX mangas_url_index ON mangas(url);
|
|
||||||
|
|
||||||
CREATE VIEW IF NOT EXISTS historyView AS
|
|
||||||
SELECT
|
|
||||||
history.history_id AS id,
|
|
||||||
mangas._id AS mangaId,
|
|
||||||
chapters._id AS chapterId,
|
|
||||||
mangas.title,
|
|
||||||
mangas.thumbnail_url AS thumnailUrl,
|
|
||||||
chapters.chapter_number AS chapterNumber,
|
|
||||||
history.history_last_read AS readAt,
|
|
||||||
max_last_read.history_last_read AS maxReadAt,
|
|
||||||
max_last_read.history_chapter_id AS maxReadAtChapterId
|
|
||||||
FROM mangas
|
|
||||||
JOIN chapters
|
|
||||||
ON mangas._id = chapters.manga_id
|
|
||||||
JOIN history
|
|
||||||
ON chapters._id = history.history_chapter_id
|
|
||||||
JOIN (
|
|
||||||
SELECT chapters.manga_id,chapters._id AS history_chapter_id, MAX(history.history_last_read) AS history_last_read
|
|
||||||
FROM chapters JOIN history
|
|
||||||
ON chapters._id = history.history_chapter_id
|
|
||||||
GROUP BY chapters.manga_id
|
|
||||||
) AS max_last_read
|
|
||||||
ON chapters.manga_id = max_last_read.manga_id;
|
|
||||||
|
|
||||||
DROP TABLE IF EXISTS manga_sync_temp;
|
|
||||||
DROP TABLE IF EXISTS mangas_categories_temp;
|
|
||||||
DROP TABLE IF EXISTS history_temp;
|
|
||||||
DROP TABLE IF EXISTS chapters_temp;
|
|
||||||
DROP TABLE IF EXISTS categories_temp;
|
|
||||||
DROP TABLE IF EXISTS manga_temp;
|
|
@ -1,52 +0,0 @@
|
|||||||
import java.util.Date;
|
|
||||||
|
|
||||||
DROP INDEX IF EXISTS history_history_chapter_id_index;
|
|
||||||
DROP VIEW IF EXISTS historyView;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* [last_read] was made not-null
|
|
||||||
* [time_read] was kept as long and made non-null
|
|
||||||
* `history` prefix was removed from table name
|
|
||||||
*/
|
|
||||||
ALTER TABLE history RENAME TO history_temp;
|
|
||||||
CREATE TABLE history(
|
|
||||||
_id INTEGER NOT NULL PRIMARY KEY,
|
|
||||||
chapter_id INTEGER NOT NULL UNIQUE,
|
|
||||||
last_read INTEGER AS Date NOT NULL,
|
|
||||||
time_read INTEGER NOT NULL,
|
|
||||||
FOREIGN KEY(chapter_id) REFERENCES chapters (_id)
|
|
||||||
ON DELETE CASCADE
|
|
||||||
);
|
|
||||||
INSERT INTO history
|
|
||||||
SELECT history_id, history_chapter_id, coalesce(history_last_read, 0), coalesce(history_time_read, 0)
|
|
||||||
FROM history_temp;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* [history.time_read] was added as a column in [historyView]
|
|
||||||
*/
|
|
||||||
CREATE VIEW historyView AS
|
|
||||||
SELECT
|
|
||||||
history._id AS id,
|
|
||||||
mangas._id AS mangaId,
|
|
||||||
chapters._id AS chapterId,
|
|
||||||
mangas.title,
|
|
||||||
mangas.thumbnail_url AS thumbnailUrl,
|
|
||||||
chapters.chapter_number AS chapterNumber,
|
|
||||||
history.last_read AS readAt,
|
|
||||||
history.time_read AS readDuration,
|
|
||||||
max_last_read.last_read AS maxReadAt,
|
|
||||||
max_last_read.chapter_id AS maxReadAtChapterId
|
|
||||||
FROM mangas
|
|
||||||
JOIN chapters
|
|
||||||
ON mangas._id = chapters.manga_id
|
|
||||||
JOIN history
|
|
||||||
ON chapters._id = history.chapter_id
|
|
||||||
JOIN (
|
|
||||||
SELECT chapters.manga_id,chapters._id AS chapter_id, MAX(history.last_read) AS last_read
|
|
||||||
FROM chapters JOIN history
|
|
||||||
ON chapters._id = history.chapter_id
|
|
||||||
GROUP BY chapters.manga_id
|
|
||||||
) AS max_last_read
|
|
||||||
ON chapters.manga_id = max_last_read.manga_id;
|
|
||||||
|
|
||||||
CREATE INDEX history_history_chapter_id_index ON history(chapter_id);
|
|
@ -1,5 +0,0 @@
|
|||||||
CREATE TABLE sources(
|
|
||||||
_id INTEGER NOT NULL PRIMARY KEY,
|
|
||||||
lang TEXT NOT NULL,
|
|
||||||
name TEXT NOT NULL
|
|
||||||
);
|
|
@ -1,29 +0,0 @@
|
|||||||
DROP VIEW IF EXISTS historyView;
|
|
||||||
|
|
||||||
CREATE VIEW historyView AS
|
|
||||||
SELECT
|
|
||||||
history._id AS id,
|
|
||||||
mangas._id AS mangaId,
|
|
||||||
chapters._id AS chapterId,
|
|
||||||
mangas.title,
|
|
||||||
mangas.thumbnail_url AS thumbnailUrl,
|
|
||||||
mangas.source,
|
|
||||||
mangas.favorite,
|
|
||||||
mangas.cover_last_modified,
|
|
||||||
chapters.chapter_number AS chapterNumber,
|
|
||||||
history.last_read AS readAt,
|
|
||||||
history.time_read AS readDuration,
|
|
||||||
max_last_read.last_read AS maxReadAt,
|
|
||||||
max_last_read.chapter_id AS maxReadAtChapterId
|
|
||||||
FROM mangas
|
|
||||||
JOIN chapters
|
|
||||||
ON mangas._id = chapters.manga_id
|
|
||||||
JOIN history
|
|
||||||
ON chapters._id = history.chapter_id
|
|
||||||
JOIN (
|
|
||||||
SELECT chapters.manga_id,chapters._id AS chapter_id, MAX(history.last_read) AS last_read
|
|
||||||
FROM chapters JOIN history
|
|
||||||
ON chapters._id = history.chapter_id
|
|
||||||
GROUP BY chapters.manga_id
|
|
||||||
) AS max_last_read
|
|
||||||
ON chapters.manga_id = max_last_read.manga_id;
|
|
@ -1,20 +0,0 @@
|
|||||||
CREATE VIEW updatesView AS
|
|
||||||
SELECT
|
|
||||||
mangas._id AS mangaId,
|
|
||||||
mangas.title AS mangaTitle,
|
|
||||||
chapters._id AS chapterId,
|
|
||||||
chapters.name AS chapterName,
|
|
||||||
chapters.scanlator,
|
|
||||||
chapters.read,
|
|
||||||
chapters.bookmark,
|
|
||||||
mangas.source,
|
|
||||||
mangas.favorite,
|
|
||||||
mangas.thumbnail_url AS thumbnailUrl,
|
|
||||||
mangas.cover_last_modified AS coverLastModified,
|
|
||||||
chapters.date_upload AS dateUpload,
|
|
||||||
chapters.date_fetch AS datefetch
|
|
||||||
FROM mangas JOIN chapters
|
|
||||||
ON mangas._id = chapters.manga_id
|
|
||||||
WHERE favorite = 1
|
|
||||||
AND date_fetch > date_added
|
|
||||||
ORDER BY date_fetch DESC;
|
|
@ -1,10 +0,0 @@
|
|||||||
-- Insert Default category
|
|
||||||
INSERT OR IGNORE INTO categories(_id, name, sort, flags) VALUES (0, "", -1, 0);
|
|
||||||
-- Disallow deletion of default category
|
|
||||||
CREATE TRIGGER IF NOT EXISTS system_category_delete_trigger BEFORE DELETE
|
|
||||||
ON categories
|
|
||||||
BEGIN SELECT CASE
|
|
||||||
WHEN old._id <= 0 THEN
|
|
||||||
RAISE(ABORT, "System category can't be deleted")
|
|
||||||
END;
|
|
||||||
END;
|
|
@ -1,10 +0,0 @@
|
|||||||
CREATE TABLE history(
|
|
||||||
history_id INTEGER NOT NULL PRIMARY KEY,
|
|
||||||
history_chapter_id INTEGER NOT NULL UNIQUE,
|
|
||||||
history_last_read INTEGER,
|
|
||||||
history_time_read INTEGER,
|
|
||||||
FOREIGN KEY(history_chapter_id) REFERENCES chapters (_id)
|
|
||||||
ON DELETE CASCADE
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE INDEX history_history_chapter_id_index ON history(history_chapter_id);
|
|
@ -1 +0,0 @@
|
|||||||
ALTER TABLE mangas ADD COLUMN update_strategy INTEGER NOT NULL DEFAULT 0;
|
|
@ -1,27 +0,0 @@
|
|||||||
CREATE VIEW libraryView AS
|
|
||||||
SELECT
|
|
||||||
M.*,
|
|
||||||
coalesce(C.total - C.readCount, 0) AS unreadCount,
|
|
||||||
coalesce(C.readCount, 0) AS readCount,
|
|
||||||
coalesce(C.latestUpload, 0) AS latestUpload,
|
|
||||||
coalesce(C.fetchedAt, 0) AS chapterFetchedAt,
|
|
||||||
coalesce(C.lastRead, 0) AS lastRead,
|
|
||||||
COALESCE(MC.category_id, 0) AS category
|
|
||||||
FROM mangas M
|
|
||||||
LEFT JOIN mangas_categories AS MC
|
|
||||||
ON MC.manga_id = M._id
|
|
||||||
LEFT JOIN(
|
|
||||||
SELECT
|
|
||||||
chapters.manga_id,
|
|
||||||
count(*) AS total,
|
|
||||||
sum(read) AS readCount,
|
|
||||||
max(chapters.date_upload) AS latestUpload,
|
|
||||||
max(history.last_read) AS lastRead,
|
|
||||||
max(chapters.date_fetch) AS fetchedAt
|
|
||||||
FROM chapters
|
|
||||||
LEFT JOIN history
|
|
||||||
ON chapters._id = history.chapter_id
|
|
||||||
GROUP BY chapters.manga_id
|
|
||||||
) AS C
|
|
||||||
ON M._id = C.manga_id
|
|
||||||
WHERE M.favorite = 1;
|
|
@ -1,31 +0,0 @@
|
|||||||
DROP VIEW libraryView;
|
|
||||||
|
|
||||||
CREATE VIEW libraryView AS
|
|
||||||
SELECT
|
|
||||||
M.*,
|
|
||||||
coalesce(C.total, 0) AS totalCount,
|
|
||||||
coalesce(C.readCount, 0) AS readCount,
|
|
||||||
coalesce(C.latestUpload, 0) AS latestUpload,
|
|
||||||
coalesce(C.fetchedAt, 0) AS chapterFetchedAt,
|
|
||||||
coalesce(C.lastRead, 0) AS lastRead,
|
|
||||||
coalesce(C.bookmarkCount, 0) AS bookmarkCount,
|
|
||||||
coalesce(MC.category_id, 0) AS category
|
|
||||||
FROM mangas M
|
|
||||||
LEFT JOIN(
|
|
||||||
SELECT
|
|
||||||
chapters.manga_id,
|
|
||||||
count(*) AS total,
|
|
||||||
sum(read) AS readCount,
|
|
||||||
coalesce(max(chapters.date_upload), 0) AS latestUpload,
|
|
||||||
coalesce(max(history.last_read), 0) AS lastRead,
|
|
||||||
coalesce(max(chapters.date_fetch), 0) AS fetchedAt,
|
|
||||||
sum(chapters.bookmark) AS bookmarkCount
|
|
||||||
FROM chapters
|
|
||||||
LEFT JOIN history
|
|
||||||
ON chapters._id = history.chapter_id
|
|
||||||
GROUP BY chapters.manga_id
|
|
||||||
) AS C
|
|
||||||
ON M._id = C.manga_id
|
|
||||||
LEFT JOIN mangas_categories AS MC
|
|
||||||
ON MC.manga_id = M._id
|
|
||||||
WHERE M.favorite = 1;
|
|
@ -1,23 +0,0 @@
|
|||||||
DROP VIEW IF EXISTS updatesView;
|
|
||||||
|
|
||||||
CREATE VIEW updatesView AS
|
|
||||||
SELECT
|
|
||||||
mangas._id AS mangaId,
|
|
||||||
mangas.title AS mangaTitle,
|
|
||||||
chapters._id AS chapterId,
|
|
||||||
chapters.name AS chapterName,
|
|
||||||
chapters.scanlator,
|
|
||||||
chapters.read,
|
|
||||||
chapters.bookmark,
|
|
||||||
chapters.last_page_read,
|
|
||||||
mangas.source,
|
|
||||||
mangas.favorite,
|
|
||||||
mangas.thumbnail_url AS thumbnailUrl,
|
|
||||||
mangas.cover_last_modified AS coverLastModified,
|
|
||||||
chapters.date_upload AS dateUpload,
|
|
||||||
chapters.date_fetch AS datefetch
|
|
||||||
FROM mangas JOIN chapters
|
|
||||||
ON mangas._id = chapters.manga_id
|
|
||||||
WHERE favorite = 1
|
|
||||||
AND date_fetch > date_added
|
|
||||||
ORDER BY date_fetch DESC;
|
|
@ -1 +0,0 @@
|
|||||||
ALTER TABLE mangas ADD COLUMN calculate_interval INTEGER DEFAULT 0 NOT NULL;
|
|
@ -1,49 +0,0 @@
|
|||||||
ALTER TABLE mangas ADD COLUMN last_modified_at INTEGER AS Long NOT NULL DEFAULT 0;
|
|
||||||
ALTER TABLE mangas ADD COLUMN favorite_modified_at INTEGER AS Long;
|
|
||||||
ALTER TABLE mangas_categories ADD COLUMN last_modified_at INTEGER AS Long NOT NULL DEFAULT 0;
|
|
||||||
ALTER TABLE chapters ADD COLUMN last_modified_at INTEGER AS Long NOT NULL DEFAULT 0;
|
|
||||||
|
|
||||||
UPDATE mangas SET last_modified_at = strftime('%s', 'now');
|
|
||||||
UPDATE mangas SET favorite_modified_at = strftime('%s', 'now') WHERE favorite = 1;
|
|
||||||
UPDATE mangas_categories SET last_modified_at = strftime('%s', 'now');
|
|
||||||
UPDATE chapters SET last_modified_at = strftime('%s', 'now');
|
|
||||||
|
|
||||||
-- Create triggers
|
|
||||||
DROP TRIGGER IF EXISTS update_last_modified_at_mangas;
|
|
||||||
CREATE TRIGGER update_last_modified_at_mangas
|
|
||||||
AFTER UPDATE ON mangas
|
|
||||||
FOR EACH ROW
|
|
||||||
BEGIN
|
|
||||||
UPDATE mangas
|
|
||||||
SET last_modified_at = strftime('%s', 'now')
|
|
||||||
WHERE _id = new._id;
|
|
||||||
END;
|
|
||||||
|
|
||||||
DROP TRIGGER IF EXISTS update_favorite_modified_at_mangas;
|
|
||||||
CREATE TRIGGER update_last_favorited_at_mangas
|
|
||||||
AFTER UPDATE OF favorite ON mangas
|
|
||||||
BEGIN
|
|
||||||
UPDATE mangas
|
|
||||||
SET favorite_modified_at = strftime('%s', 'now')
|
|
||||||
WHERE _id = new._id;
|
|
||||||
END;
|
|
||||||
|
|
||||||
DROP TRIGGER IF EXISTS update_last_modified_at_chapters;
|
|
||||||
CREATE TRIGGER update_last_modified_at_chapters
|
|
||||||
AFTER UPDATE ON chapters
|
|
||||||
FOR EACH ROW
|
|
||||||
BEGIN
|
|
||||||
UPDATE chapters
|
|
||||||
SET last_modified_at = strftime('%s', 'now')
|
|
||||||
WHERE _id = new._id;
|
|
||||||
END;
|
|
||||||
|
|
||||||
DROP TRIGGER IF EXISTS update_last_modified_at_mangas_categories;
|
|
||||||
CREATE TRIGGER update_last_modified_at_mangas_categories
|
|
||||||
AFTER UPDATE ON mangas_categories
|
|
||||||
FOR EACH ROW
|
|
||||||
BEGIN
|
|
||||||
UPDATE mangas_categories
|
|
||||||
SET last_modified_at = strftime('%s', 'now')
|
|
||||||
WHERE _id = new._id;
|
|
||||||
END;
|
|
@ -1,44 +0,0 @@
|
|||||||
CREATE TABLE excluded_scanlators(
|
|
||||||
manga_id INTEGER NOT NULL,
|
|
||||||
scanlator TEXT NOT NULL,
|
|
||||||
FOREIGN KEY(manga_id) REFERENCES mangas (_id)
|
|
||||||
ON DELETE CASCADE
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE INDEX excluded_scanlators_manga_id_index ON excluded_scanlators(manga_id);
|
|
||||||
|
|
||||||
DROP VIEW IF EXISTS libraryView;
|
|
||||||
|
|
||||||
CREATE VIEW libraryView AS
|
|
||||||
SELECT
|
|
||||||
M.*,
|
|
||||||
coalesce(C.total, 0) AS totalCount,
|
|
||||||
coalesce(C.readCount, 0) AS readCount,
|
|
||||||
coalesce(C.latestUpload, 0) AS latestUpload,
|
|
||||||
coalesce(C.fetchedAt, 0) AS chapterFetchedAt,
|
|
||||||
coalesce(C.lastRead, 0) AS lastRead,
|
|
||||||
coalesce(C.bookmarkCount, 0) AS bookmarkCount,
|
|
||||||
coalesce(MC.category_id, 0) AS category
|
|
||||||
FROM mangas M
|
|
||||||
LEFT JOIN(
|
|
||||||
SELECT
|
|
||||||
chapters.manga_id,
|
|
||||||
count(*) AS total,
|
|
||||||
sum(read) AS readCount,
|
|
||||||
coalesce(max(chapters.date_upload), 0) AS latestUpload,
|
|
||||||
coalesce(max(history.last_read), 0) AS lastRead,
|
|
||||||
coalesce(max(chapters.date_fetch), 0) AS fetchedAt,
|
|
||||||
sum(chapters.bookmark) AS bookmarkCount
|
|
||||||
FROM chapters
|
|
||||||
LEFT JOIN excluded_scanlators
|
|
||||||
ON chapters.manga_id = excluded_scanlators.manga_id
|
|
||||||
AND chapters.scanlator = excluded_scanlators.scanlator
|
|
||||||
LEFT JOIN history
|
|
||||||
ON chapters._id = history.chapter_id
|
|
||||||
WHERE excluded_scanlators.scanlator IS NULL
|
|
||||||
GROUP BY chapters.manga_id
|
|
||||||
) AS C
|
|
||||||
ON M._id = C.manga_id
|
|
||||||
LEFT JOIN mangas_categories AS MC
|
|
||||||
ON MC.manga_id = M._id
|
|
||||||
WHERE M.favorite = 1;
|
|
@ -1,3 +0,0 @@
|
|||||||
UPDATE chapters
|
|
||||||
SET scanlator = trim(scanlator)
|
|
||||||
WHERE scanlator IS NOT NULL;
|
|
@ -1,2 +0,0 @@
|
|||||||
ALTER TABLE chapters
|
|
||||||
ADD COLUMN bookmark INTEGER DEFAULT 0;
|
|
@ -1,2 +0,0 @@
|
|||||||
ALTER TABLE chapters
|
|
||||||
ADD COLUMN scanlator TEXT DEFAULT NULL;
|
|
@ -1,2 +0,0 @@
|
|||||||
ALTER TABLE manga_sync
|
|
||||||
ADD COLUMN remote_url TEXT DEFAULT '';
|
|
@ -1,2 +0,0 @@
|
|||||||
ALTER TABLE manga_sync
|
|
||||||
ADD COLUMN library_id INTEGER;
|
|
@ -1,9 +0,0 @@
|
|||||||
DROP INDEX IF EXISTS mangas_favorite_index;
|
|
||||||
|
|
||||||
CREATE INDEX library_favorite_index
|
|
||||||
ON mangas(favorite)
|
|
||||||
WHERE favorite = 1;
|
|
||||||
|
|
||||||
CREATE INDEX chapters_unread_by_manga_index
|
|
||||||
ON chapters(manga_id, read)
|
|
||||||
WHERE read = 0;
|
|
@ -1,5 +0,0 @@
|
|||||||
ALTER TABLE manga_sync
|
|
||||||
ADD COLUMN start_date INTEGER NOT NULL DEFAULT 0;
|
|
||||||
|
|
||||||
ALTER TABLE manga_sync
|
|
||||||
ADD COLUMN finish_date INTEGER NOT NULL DEFAULT 0;
|
|
@ -1,2 +0,0 @@
|
|||||||
ALTER TABLE mangas
|
|
||||||
ADD COLUMN cover_last_modified INTEGER NOT NULL DEFAULT 0;
|
|
Loading…
Reference in New Issue
Block a user