diff --git a/CHANGELOG.md b/CHANGELOG.md index 53f9ae9..e60ebe0 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Security +## [2.0.0-rc13] - 2021-02-19 +### Changed +- [2021-02-19] Back to sqlite we go [@carbotaniuman]. + ## [2.0.0-rc12] - 2021-02-11 ### Fixed - [2021-02-11] Fixed stupid cross platform bug [@carbotaniuman]. @@ -361,7 +365,8 @@ This release contains many breaking changes! Of note are the changes to the cach ### Fixed - [2020-06-11] Tweaked logging configuration to reduce log file sizes by [@carbotaniuman]. -[Unreleased]: https://gitlab.com/mangadex/mangadex_at_home/-/compare/2.0.0-rc12...HEAD +[Unreleased]: https://gitlab.com/mangadex/mangadex_at_home/-/compare/2.0.0-rc13...HEAD +[2.0.0-rc13]: https://gitlab.com/mangadex/mangadex_at_home/-/compare/2.0.0-rc12...2.0.0-rc13 [2.0.0-rc12]: https://gitlab.com/mangadex/mangadex_at_home/-/compare/2.0.0-rc11...2.0.0-rc12 [2.0.0-rc11]: https://gitlab.com/mangadex/mangadex_at_home/-/compare/2.0.0-rc10...2.0.0-rc11 [2.0.0-rc10]: https://gitlab.com/mangadex/mangadex_at_home/-/compare/2.0.0-rc9...2.0.0-rc10 diff --git a/build.gradle b/build.gradle index e2b417c..bb2d8de 100644 --- a/build.gradle +++ b/build.gradle @@ -48,6 +48,7 @@ dependencies { implementation group: 'com.zaxxer', name: 'HikariCP', version: '4.0.1' implementation group: "com.h2database", name: "h2", version: "1.4.200" + implementation group: 'org.xerial', name: 'sqlite-jdbc', version: '3.34.0' implementation "org.ktorm:ktorm-core:$ktorm_version" implementation "org.ktorm:ktorm-jackson:$ktorm_version" diff --git a/src/main/kotlin/mdnet/Constants.kt b/src/main/kotlin/mdnet/Constants.kt index 15e7d8b..1d5d7b4 100644 --- a/src/main/kotlin/mdnet/Constants.kt +++ b/src/main/kotlin/mdnet/Constants.kt @@ -21,7 +21,7 @@ package mdnet import java.time.Duration object Constants { - const val CLIENT_BUILD = 27 + const val CLIENT_BUILD = 28 @JvmField val MAX_AGE_CACHE: Duration = Duration.ofDays(14) diff --git a/src/main/kotlin/mdnet/Main.kt b/src/main/kotlin/mdnet/Main.kt index 7c0125f..c4ba540 100644 --- a/src/main/kotlin/mdnet/Main.kt +++ b/src/main/kotlin/mdnet/Main.kt @@ -94,6 +94,8 @@ class Main : Runnable { throw IllegalArgumentException("Cache folder $cacheFolder must be a directory") } + migrate(databaseFolder) + val client = MangaDexClient(settingsFile, databaseFolder, cacheFolder) val hook = Thread { client.shutdown() diff --git a/src/main/kotlin/mdnet/MangaDexClient.kt b/src/main/kotlin/mdnet/MangaDexClient.kt index 40b7b5b..c6f498c 100644 --- a/src/main/kotlin/mdnet/MangaDexClient.kt +++ b/src/main/kotlin/mdnet/MangaDexClient.kt @@ -65,9 +65,11 @@ class MangaDexClient(private val settingsFile: File, databaseFolder: Path, cache LOGGER.info { "Client settings loaded: $settings" } + Class.forName("org.sqlite.JDBC") + val config = HikariConfig() - val db = databaseFolder.resolve("metadata") - config.jdbcUrl = "jdbc:h2:$db" + val db = databaseFolder.resolve("metadata.db") + config.jdbcUrl = "jdbc:sqlite:$db" config.addDataSourceProperty("cachePrepStmts", "true") config.addDataSourceProperty("prepStmtCacheSize", "100") config.addDataSourceProperty("prepStmtCacheSqlLimit", "1000") diff --git a/src/main/kotlin/mdnet/Migrator.kt b/src/main/kotlin/mdnet/Migrator.kt new file mode 100644 index 0000000..58d926d --- /dev/null +++ b/src/main/kotlin/mdnet/Migrator.kt @@ -0,0 +1,73 @@ +/* +Mangadex@Home +Copyright (c) 2020, MangaDex Network +This file is part of MangaDex@Home. + +MangaDex@Home is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +MangaDex@Home is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this MangaDex@Home. If not, see . +*/ +package mdnet + +import mdnet.cache.DbImage +import mdnet.cache.INIT_TABLE +import org.ktorm.database.Database +import org.ktorm.dsl.* +import java.nio.file.Files +import java.nio.file.Path +import java.nio.file.Paths + +fun main() { + migrate(Paths.get("./")) +} + +fun migrate(path: Path) { + val h2file = path.resolve("metadata.mv.db") + if (!Files.exists(h2file)) { + return + } + + println("Migrating database - this may take a long time") + + Class.forName("org.sqlite.JDBC") + + val sqliteDb = path.resolve("metadata.db") + Files.delete(sqliteDb) + + val sqlite = Database.connect("jdbc:sqlite:$sqliteDb") + sqlite.useConnection { conn -> + conn.prepareStatement(INIT_TABLE).use { + it.execute() + } + } + + val db = path.resolve("metadata") + + val h2 = Database.connect("jdbc:h2:$db") + h2.useConnection { conn -> + conn.prepareStatement(INIT_TABLE).use { + it.execute() + } + } + + sqlite.batchInsert(DbImage) { + h2.from(DbImage).select().forEach { data -> + item { + set(DbImage.id, data[DbImage.id]) + set(DbImage.accessed, data[DbImage.accessed]) + set(DbImage.size, data[DbImage.size]) + } + } + } + + Files.move(h2file, path.resolve("metadata.mv.db.old")) +}