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") implementation("com.h2database:h2:1.4.200")
// Exposed Migrations // Exposed Migrations
val exposedMigrationsVersion = "3.0.0" val exposedMigrationsVersion = "3.1.0"
implementation("com.github.Suwayomi:exposed-migrations:$exposedMigrationsVersion") implementation("com.github.Suwayomi:exposed-migrations:$exposedMigrationsVersion")
// tray icon // 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 * 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/. */ * 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 eu.kanade.tachiyomi.source.model.SManga
import org.jetbrains.exposed.dao.id.IdTable import org.jetbrains.exposed.dao.id.IdTable
import org.jetbrains.exposed.dao.id.IntIdTable import org.jetbrains.exposed.dao.id.IntIdTable
import org.jetbrains.exposed.sql.SchemaUtils import org.jetbrains.exposed.sql.Table
import org.jetbrains.exposed.sql.transactions.transaction
@Suppress("ClassName", "unused") @Suppress("ClassName", "unused")
class M0001_Initial : Migration() { /** initial migration, create all tables */
class M0001_Initial : AddTableMigration() {
private class ExtensionTable : IntIdTable() { private class ExtensionTable : IntIdTable() {
init { init {
varchar("apk_name", 1024) varchar("apk_name", 1024)
@@ -111,9 +112,8 @@ class M0001_Initial : Migration() {
} }
} }
/** initial migration, create all tables */ override val tables: Array<Table>
override fun run() { get() {
transaction {
val extensionTable = ExtensionTable() val extensionTable = ExtensionTable()
val sourceTable = SourceTable(extensionTable) val sourceTable = SourceTable(extensionTable)
val mangaTable = MangaTable() val mangaTable = MangaTable()
@@ -121,7 +121,8 @@ class M0001_Initial : Migration() {
val pageTable = PageTable(chapterTable) val pageTable = PageTable(chapterTable)
val categoryTable = CategoryTable() val categoryTable = CategoryTable()
val categoryMangaTable = CategoryMangaTable(categoryTable, mangaTable) val categoryMangaTable = CategoryMangaTable(categoryTable, mangaTable)
SchemaUtils.create(
return arrayOf(
extensionTable, extensionTable,
sourceTable, sourceTable,
mangaTable, mangaTable,
@@ -131,5 +132,4 @@ class M0001_Initial : Migration() {
categoryMangaTable, 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 * 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/. */ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
import de.neonew.exposed.migrations.Migration import de.neonew.exposed.migrations.helpers.RenameFieldMigration
import org.jetbrains.exposed.sql.transactions.TransactionManager
import org.jetbrains.exposed.sql.vendors.currentDialect
@Suppress("ClassName", "unused") @Suppress("ClassName", "unused")
class M0002_ChapterTableIndexRename : Migration() { class M0002_ChapterTableIndexRename : RenameFieldMigration(
/** this migration renamed ChapterTable.NUMBER_IN_LIST to ChapterTable.INDEX */ "Chapter",
override fun run() { "number_in_list",
with(TransactionManager.current()) { "index"
exec("ALTER TABLE CHAPTER ALTER COLUMN NUMBER_IN_LIST RENAME TO INDEX") )
commit()
currentDialect.resetCaches()
}
}
}

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 * 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/. */ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
import de.neonew.exposed.migrations.Migration import de.neonew.exposed.migrations.helpers.RenameFieldMigration
import org.jetbrains.exposed.sql.transactions.TransactionManager
import org.jetbrains.exposed.sql.vendors.currentDialect
@Suppress("ClassName", "unused") @Suppress("ClassName", "unused")
class M0003_DefaultCategory : Migration() { class M0003_DefaultCategory : RenameFieldMigration(
/** this migration renamed CategoryTable.IS_LANDING to ChapterTable.IS_DEFAULT */ "Category",
override fun run() { "is_landing",
with(TransactionManager.current()) { "is_default"
exec("ALTER TABLE CATEGORY ALTER COLUMN IS_LANDING RENAME TO IS_DEFAULT") )
commit()
currentDialect.resetCaches()
}
}
}

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 * 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/. */ * 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.IdTable
import org.jetbrains.exposed.dao.id.IntIdTable import org.jetbrains.exposed.dao.id.IntIdTable
import org.jetbrains.exposed.sql.SchemaUtils import org.jetbrains.exposed.sql.Table
import org.jetbrains.exposed.sql.transactions.transaction
@Suppress("ClassName", "unused") @Suppress("ClassName", "unused")
class M0004_AnimeTablesBatch1 : Migration() { class M0004_AnimeTablesBatch1 : AddTableMigration() {
private class AnimeExtensionTable : IntIdTable() { private class AnimeExtensionTable : IntIdTable() {
val apkName = varchar("apk_name", 1024) val apkName = varchar("apk_name", 1024)
@@ -44,12 +43,9 @@ class M0004_AnimeTablesBatch1 : Migration() {
val partOfFactorySource = bool("part_of_factory_source").default(false) val partOfFactorySource = bool("part_of_factory_source").default(false)
} }
override fun run() { override val tables: Array<Table>
transaction { get() = arrayOf(
SchemaUtils.create( AnimeExtensionTable(),
AnimeExtensionTable(), AnimeSourceTable()
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 * 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/. */ * 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 eu.kanade.tachiyomi.animesource.model.SAnime
import org.jetbrains.exposed.dao.id.IntIdTable import org.jetbrains.exposed.dao.id.IntIdTable
import org.jetbrains.exposed.sql.SchemaUtils import org.jetbrains.exposed.sql.Table
import org.jetbrains.exposed.sql.transactions.transaction
@Suppress("ClassName", "unused") @Suppress("ClassName", "unused")
class M0005_AnimeTablesBatch2 : Migration() { class M0005_AnimeTablesBatch2 : AddTableMigration() {
private class AnimeTable : IntIdTable() { private class AnimeTable : IntIdTable() {
val url = varchar("url", 2048) val url = varchar("url", 2048)
val title = varchar("title", 512) val title = varchar("title", 512)
@@ -36,11 +35,8 @@ class M0005_AnimeTablesBatch2 : Migration() {
val sourceReference = long("source") val sourceReference = long("source")
} }
override fun run() { override val tables: Array<Table>
transaction { get() = arrayOf(
SchemaUtils.create( AnimeTable()
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 * 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/. */ * 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.dao.id.IntIdTable
import org.jetbrains.exposed.sql.SchemaUtils import org.jetbrains.exposed.sql.Table
import org.jetbrains.exposed.sql.transactions.transaction
import suwayomi.tachidesk.anime.model.table.AnimeTable import suwayomi.tachidesk.anime.model.table.AnimeTable
@Suppress("ClassName", "unused") @Suppress("ClassName", "unused")
class M0006_AnimeTablesBatch3 : Migration() { class M0006_AnimeTablesBatch3 : AddTableMigration() {
private class EpisodeTable : IntIdTable() { private class EpisodeTable : IntIdTable() {
val url = varchar("url", 2048) val url = varchar("url", 2048)
val name = varchar("name", 512) val name = varchar("name", 512)
@@ -32,11 +31,8 @@ class M0006_AnimeTablesBatch3 : Migration() {
val anime = reference("anime", AnimeTable) val anime = reference("anime", AnimeTable)
} }
override fun run() { override val tables: Array<Table>
transaction { get() = arrayOf(
SchemaUtils.create( EpisodeTable()
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 * 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/. */ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
import de.neonew.exposed.migrations.Migration import de.neonew.exposed.migrations.helpers.AddColumnMigration
import org.jetbrains.exposed.sql.transactions.TransactionManager
import org.jetbrains.exposed.sql.vendors.currentDialect
@Suppress("ClassName", "unused") @Suppress("ClassName", "unused")
class M0007_ChapterIsDownloaded : Migration() { class M0007_ChapterIsDownloaded : AddColumnMigration(
/** this migration added IS_DOWNLOADED to CHAPTER */ "Chapter",
override fun run() { "is_downloaded",
with(TransactionManager.current()) { "BOOLEAN",
exec("ALTER TABLE CHAPTER ADD COLUMN IS_DOWNLOADED BOOLEAN DEFAULT FALSE") "FALSE"
commit() )
currentDialect.resetCaches()
}
}
}

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 * 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/. */ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
import de.neonew.exposed.migrations.Migration import de.neonew.exposed.migrations.helpers.AddColumnMigration
import org.jetbrains.exposed.sql.transactions.TransactionManager
import org.jetbrains.exposed.sql.vendors.currentDialect
@Suppress("ClassName", "unused") @Suppress("ClassName", "unused")
class M0008_ChapterPageCount : Migration() { class M0008_ChapterPageCount : AddColumnMigration(
/** this migration added PAGE_COUNT to CHAPTER */ "Chapter",
override fun run() { "page_count",
with(TransactionManager.current()) { "INT",
exec("ALTER TABLE CHAPTER ADD COLUMN PAGE_COUNT INT DEFAULT -1") "-1"
commit() )
currentDialect.resetCaches()
}
}
}

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 * 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/. */ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
import de.neonew.exposed.migrations.Migration import de.neonew.exposed.migrations.helpers.AddColumnMigration
import org.jetbrains.exposed.sql.transactions.TransactionManager
import org.jetbrains.exposed.sql.vendors.currentDialect
@Suppress("ClassName", "unused") @Suppress("ClassName", "unused")
class M0009_ChapterLastReadAt : Migration() { class M0009_ChapterLastReadAt : AddColumnMigration(
/** this migration added PAGE_COUNT to CHAPTER */ "Chapter",
override fun run() { "last_read_at",
with(TransactionManager.current()) { "BIGINT", // BIGINT == Long
// BIGINT == Long "0"
exec("ALTER TABLE CHAPTER ADD COLUMN LAST_READ_AT BIGINT DEFAULT 0") )
commit()
currentDialect.resetCaches()
}
}
}

View File

@@ -1,13 +1,5 @@
package suwayomi.tachidesk.server.database.migration 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 * Copyright (C) Contributors to the Suwayomi project
* *
@@ -15,25 +7,30 @@ import suwayomi.tachidesk.manga.model.table.MangaTable
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * 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") @Suppress("ClassName", "unused")
class M0010_MangaAndChapterMeta : Migration() { class M0010_MangaAndChapterMeta : AddTableMigration() {
private class ChapterMetaTable : IntIdTable() { private class ChapterMetaTable : IntIdTable() {
val key = varchar("key", 256) val key = varchar("key", 256)
val value = varchar("value", 4096) val value = varchar("value", 4096)
val ref = reference("chapter_ref", ChapterTable, ReferenceOption.CASCADE) val ref = reference("chapter_ref", ChapterTable, ReferenceOption.CASCADE)
} }
private class MangaMetaTable : IntIdTable() { private class MangaMetaTable : IntIdTable() {
val key = varchar("key", 256) val key = varchar("key", 256)
val value = varchar("value", 4096) val value = varchar("value", 4096)
val ref = reference("manga_ref", MangaTable, ReferenceOption.CASCADE) val ref = reference("manga_ref", MangaTable, ReferenceOption.CASCADE)
} }
override fun run() { override val tables: Array<Table>
transaction { get() = arrayOf(
SchemaUtils.create( ChapterMetaTable(),
ChapterMetaTable(), MangaMetaTable()
MangaMetaTable() )
)
}
}
} }