refactor to fancy migration classes

This commit is contained in:
Aria Moradi
2021-08-07 21:58:36 +04:30
parent 568fa56d59
commit b51651ace4
11 changed files with 80 additions and 128 deletions

View File

@@ -45,7 +45,7 @@ dependencies {
implementation("com.h2database:h2:1.4.200")
// Exposed Migrations
val exposedMigrationsVersion = "3.0.0"
val exposedMigrationsVersion = "3.1.0"
implementation("com.github.Suwayomi:exposed-migrations:$exposedMigrationsVersion")
// tray icon

View File

@@ -7,15 +7,16 @@ package suwayomi.tachidesk.server.database.migration
* 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/. */
import de.neonew.exposed.migrations.Migration
import de.neonew.exposed.migrations.helpers.AddTableMigration
import eu.kanade.tachiyomi.source.model.SManga
import org.jetbrains.exposed.dao.id.IdTable
import org.jetbrains.exposed.dao.id.IntIdTable
import org.jetbrains.exposed.sql.SchemaUtils
import org.jetbrains.exposed.sql.transactions.transaction
import org.jetbrains.exposed.sql.Table
@Suppress("ClassName", "unused")
class M0001_Initial : Migration() {
/** initial migration, create all tables */
class M0001_Initial : AddTableMigration() {
private class ExtensionTable : IntIdTable() {
init {
varchar("apk_name", 1024)
@@ -111,9 +112,8 @@ class M0001_Initial : Migration() {
}
}
/** initial migration, create all tables */
override fun run() {
transaction {
override val tables: Array<Table>
get() {
val extensionTable = ExtensionTable()
val sourceTable = SourceTable(extensionTable)
val mangaTable = MangaTable()
@@ -121,7 +121,8 @@ class M0001_Initial : Migration() {
val pageTable = PageTable(chapterTable)
val categoryTable = CategoryTable()
val categoryMangaTable = CategoryMangaTable(categoryTable, mangaTable)
SchemaUtils.create(
return arrayOf(
extensionTable,
sourceTable,
mangaTable,
@@ -131,5 +132,4 @@ class M0001_Initial : Migration() {
categoryMangaTable,
)
}
}
}

View File

@@ -7,18 +7,11 @@ package suwayomi.tachidesk.server.database.migration
* 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/. */
import de.neonew.exposed.migrations.Migration
import org.jetbrains.exposed.sql.transactions.TransactionManager
import org.jetbrains.exposed.sql.vendors.currentDialect
import de.neonew.exposed.migrations.helpers.RenameFieldMigration
@Suppress("ClassName", "unused")
class M0002_ChapterTableIndexRename : Migration() {
/** this migration renamed ChapterTable.NUMBER_IN_LIST to ChapterTable.INDEX */
override fun run() {
with(TransactionManager.current()) {
exec("ALTER TABLE CHAPTER ALTER COLUMN NUMBER_IN_LIST RENAME TO INDEX")
commit()
currentDialect.resetCaches()
}
}
}
class M0002_ChapterTableIndexRename : RenameFieldMigration(
"Chapter",
"number_in_list",
"index"
)

View File

@@ -7,18 +7,11 @@ package suwayomi.tachidesk.server.database.migration
* 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/. */
import de.neonew.exposed.migrations.Migration
import org.jetbrains.exposed.sql.transactions.TransactionManager
import org.jetbrains.exposed.sql.vendors.currentDialect
import de.neonew.exposed.migrations.helpers.RenameFieldMigration
@Suppress("ClassName", "unused")
class M0003_DefaultCategory : Migration() {
/** this migration renamed CategoryTable.IS_LANDING to ChapterTable.IS_DEFAULT */
override fun run() {
with(TransactionManager.current()) {
exec("ALTER TABLE CATEGORY ALTER COLUMN IS_LANDING RENAME TO IS_DEFAULT")
commit()
currentDialect.resetCaches()
}
}
}
class M0003_DefaultCategory : RenameFieldMigration(
"Category",
"is_landing",
"is_default"
)

View File

@@ -7,14 +7,13 @@ package suwayomi.tachidesk.server.database.migration
* 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/. */
import de.neonew.exposed.migrations.Migration
import de.neonew.exposed.migrations.helpers.AddTableMigration
import org.jetbrains.exposed.dao.id.IdTable
import org.jetbrains.exposed.dao.id.IntIdTable
import org.jetbrains.exposed.sql.SchemaUtils
import org.jetbrains.exposed.sql.transactions.transaction
import org.jetbrains.exposed.sql.Table
@Suppress("ClassName", "unused")
class M0004_AnimeTablesBatch1 : Migration() {
class M0004_AnimeTablesBatch1 : AddTableMigration() {
private class AnimeExtensionTable : IntIdTable() {
val apkName = varchar("apk_name", 1024)
@@ -44,12 +43,9 @@ class M0004_AnimeTablesBatch1 : Migration() {
val partOfFactorySource = bool("part_of_factory_source").default(false)
}
override fun run() {
transaction {
SchemaUtils.create(
AnimeExtensionTable(),
AnimeSourceTable()
)
}
}
override val tables: Array<Table>
get() = arrayOf(
AnimeExtensionTable(),
AnimeSourceTable()
)
}

View File

@@ -7,14 +7,13 @@ package suwayomi.tachidesk.server.database.migration
* 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/. */
import de.neonew.exposed.migrations.Migration
import de.neonew.exposed.migrations.helpers.AddTableMigration
import eu.kanade.tachiyomi.animesource.model.SAnime
import org.jetbrains.exposed.dao.id.IntIdTable
import org.jetbrains.exposed.sql.SchemaUtils
import org.jetbrains.exposed.sql.transactions.transaction
import org.jetbrains.exposed.sql.Table
@Suppress("ClassName", "unused")
class M0005_AnimeTablesBatch2 : Migration() {
class M0005_AnimeTablesBatch2 : AddTableMigration() {
private class AnimeTable : IntIdTable() {
val url = varchar("url", 2048)
val title = varchar("title", 512)
@@ -36,11 +35,8 @@ class M0005_AnimeTablesBatch2 : Migration() {
val sourceReference = long("source")
}
override fun run() {
transaction {
SchemaUtils.create(
AnimeTable()
)
}
}
override val tables: Array<Table>
get() = arrayOf(
AnimeTable()
)
}

View File

@@ -7,14 +7,13 @@ package suwayomi.tachidesk.server.database.migration
* 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/. */
import de.neonew.exposed.migrations.Migration
import de.neonew.exposed.migrations.helpers.AddTableMigration
import org.jetbrains.exposed.dao.id.IntIdTable
import org.jetbrains.exposed.sql.SchemaUtils
import org.jetbrains.exposed.sql.transactions.transaction
import org.jetbrains.exposed.sql.Table
import suwayomi.tachidesk.anime.model.table.AnimeTable
@Suppress("ClassName", "unused")
class M0006_AnimeTablesBatch3 : Migration() {
class M0006_AnimeTablesBatch3 : AddTableMigration() {
private class EpisodeTable : IntIdTable() {
val url = varchar("url", 2048)
val name = varchar("name", 512)
@@ -32,11 +31,8 @@ class M0006_AnimeTablesBatch3 : Migration() {
val anime = reference("anime", AnimeTable)
}
override fun run() {
transaction {
SchemaUtils.create(
EpisodeTable()
)
}
}
override val tables: Array<Table>
get() = arrayOf(
EpisodeTable()
)
}

View File

@@ -7,18 +7,12 @@ package suwayomi.tachidesk.server.database.migration
* 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/. */
import de.neonew.exposed.migrations.Migration
import org.jetbrains.exposed.sql.transactions.TransactionManager
import org.jetbrains.exposed.sql.vendors.currentDialect
import de.neonew.exposed.migrations.helpers.AddColumnMigration
@Suppress("ClassName", "unused")
class M0007_ChapterIsDownloaded : Migration() {
/** this migration added IS_DOWNLOADED to CHAPTER */
override fun run() {
with(TransactionManager.current()) {
exec("ALTER TABLE CHAPTER ADD COLUMN IS_DOWNLOADED BOOLEAN DEFAULT FALSE")
commit()
currentDialect.resetCaches()
}
}
}
class M0007_ChapterIsDownloaded : AddColumnMigration(
"Chapter",
"is_downloaded",
"BOOLEAN",
"FALSE"
)

View File

@@ -7,18 +7,12 @@ package suwayomi.tachidesk.server.database.migration
* 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/. */
import de.neonew.exposed.migrations.Migration
import org.jetbrains.exposed.sql.transactions.TransactionManager
import org.jetbrains.exposed.sql.vendors.currentDialect
import de.neonew.exposed.migrations.helpers.AddColumnMigration
@Suppress("ClassName", "unused")
class M0008_ChapterPageCount : Migration() {
/** this migration added PAGE_COUNT to CHAPTER */
override fun run() {
with(TransactionManager.current()) {
exec("ALTER TABLE CHAPTER ADD COLUMN PAGE_COUNT INT DEFAULT -1")
commit()
currentDialect.resetCaches()
}
}
}
class M0008_ChapterPageCount : AddColumnMigration(
"Chapter",
"page_count",
"INT",
"-1"
)

View File

@@ -7,19 +7,12 @@ package suwayomi.tachidesk.server.database.migration
* 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/. */
import de.neonew.exposed.migrations.Migration
import org.jetbrains.exposed.sql.transactions.TransactionManager
import org.jetbrains.exposed.sql.vendors.currentDialect
import de.neonew.exposed.migrations.helpers.AddColumnMigration
@Suppress("ClassName", "unused")
class M0009_ChapterLastReadAt : Migration() {
/** this migration added PAGE_COUNT to CHAPTER */
override fun run() {
with(TransactionManager.current()) {
// BIGINT == Long
exec("ALTER TABLE CHAPTER ADD COLUMN LAST_READ_AT BIGINT DEFAULT 0")
commit()
currentDialect.resetCaches()
}
}
}
class M0009_ChapterLastReadAt : AddColumnMigration(
"Chapter",
"last_read_at",
"BIGINT", // BIGINT == Long
"0"
)

View File

@@ -1,39 +1,36 @@
package suwayomi.tachidesk.server.database.migration
import de.neonew.exposed.migrations.Migration
import org.jetbrains.exposed.dao.id.IntIdTable
import org.jetbrains.exposed.sql.ReferenceOption
import org.jetbrains.exposed.sql.SchemaUtils
import org.jetbrains.exposed.sql.transactions.transaction
import suwayomi.tachidesk.manga.model.table.ChapterTable
import suwayomi.tachidesk.manga.model.table.MangaTable
/*
* Copyright (C) Contributors to the Suwayomi project
*
*
* 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/. */
import de.neonew.exposed.migrations.helpers.AddTableMigration
import org.jetbrains.exposed.dao.id.IntIdTable
import org.jetbrains.exposed.sql.ReferenceOption
import org.jetbrains.exposed.sql.Table
import suwayomi.tachidesk.manga.model.table.ChapterTable
import suwayomi.tachidesk.manga.model.table.MangaTable
@Suppress("ClassName", "unused")
class M0010_MangaAndChapterMeta : Migration() {
class M0010_MangaAndChapterMeta : AddTableMigration() {
private class ChapterMetaTable : IntIdTable() {
val key = varchar("key", 256)
val value = varchar("value", 4096)
val ref = reference("chapter_ref", ChapterTable, ReferenceOption.CASCADE)
}
private class MangaMetaTable : IntIdTable() {
val key = varchar("key", 256)
val value = varchar("value", 4096)
val ref = reference("manga_ref", MangaTable, ReferenceOption.CASCADE)
}
override fun run() {
transaction {
SchemaUtils.create(
ChapterMetaTable(),
MangaMetaTable()
)
}
}
override val tables: Array<Table>
get() = arrayOf(
ChapterMetaTable(),
MangaMetaTable()
)
}