package eu.friedcutlet.yokan.database.room import androidx.room.ColumnInfo import androidx.room.ConstructedBy import androidx.room.Dao import androidx.room.Database import androidx.room.Entity import androidx.room.ForeignKey import androidx.room.Insert import androidx.room.OnConflictStrategy import androidx.room.PrimaryKey import androidx.room.Query import androidx.room.RoomDatabase import androidx.room.RoomDatabaseConstructor import androidx.room.Upsert import androidx.room.migration.Migration import androidx.sqlite.SQLiteConnection import androidx.sqlite.driver.bundled.BundledSQLiteDriver import androidx.sqlite.execSQL import eu.friedcutlet.yokan.database.DbSettings // ─── Entity schemas ───────────────────────────────────────────────────────── // One Row class per logical table. Complex types (enums, List, // nested objects) are stored as JSON TEXT columns and translated in // `RowAdapters.kt`; the schema stays plain SQL primitives so Room's KSP // processor doesn't need TypeConverters. @Entity(tableName = "manga") data class MangaRow( @PrimaryKey val id: Long, val name: String? = null, val link: String? = null, val imageUrl: String? = null, val description: String? = null, val author: String? = null, val artist: String? = null, val status: String, val itemType: String, val genre: String? = null, val favorite: Boolean = false, val source: String? = null, val lang: String? = null, val dateAdded: Long? = null, val lastUpdate: Long? = null, val lastRead: Long = 0, val categories: String? = null, val isLocalArchive: Boolean = false, val customCoverImage: ByteArray? = null, val customCoverFromTracker: String? = null, val smartUpdateDays: Int? = null, val updatedAt: Long = 0, val sourceId: Long? = null, @ColumnInfo(defaultValue = "''") val privateNote: String = "", @ColumnInfo(defaultValue = "0") val nextEpisodeAiringAt: Long = 0, @ColumnInfo(defaultValue = "NULL") val nextEpisodeNumber: Int? = null, @ColumnInfo(defaultValue = "0") val airingScheduleUpdatedAt: Long = 0, @ColumnInfo(defaultValue = "NULL") val parentId: Long? = null, @ColumnInfo(defaultValue = "'Episodes'") val fetchType: String = "Episodes", @ColumnInfo(defaultValue = "NULL") val seasonNumber: Double? = null, ) @Entity( tableName = "manga_credit", primaryKeys = ["mangaId", "position"], foreignKeys = [ForeignKey(entity = MangaRow::class, parentColumns = ["id"], childColumns = ["mangaId"], onDelete = ForeignKey.CASCADE)], ) data class MangaCreditRow( val mangaId: Long, val position: Int, val name: String, val role: String? = null, val character: String? = null, val imageUrl: String? = null, ) @Dao interface MangaCreditDao { @Query("SELECT * FROM manga_credit ORDER BY mangaId, position") suspend fun all(): List @Upsert suspend fun upsertAll(rows: List) @Query("DELETE FROM manga_credit WHERE mangaId = :mangaId") suspend fun deleteForManga(mangaId: Long) @Query("DELETE FROM manga_credit") suspend fun clear() } @Entity(tableName = "chapter") data class ChapterRow( @PrimaryKey val id: Long, val mangaId: Long? = null, val name: String? = null, val url: String = "", val dateUpload: String = "", val scanlator: String = "", val isBookmarked: Boolean = false, val isRead: Boolean = false, val lastPageRead: String = "", val archivePath: String = "", val isFiller: Boolean = false, val thumbnailUrl: String? = null, val description: String? = null, val downloadSize: String? = null, val duration: String? = null, val updatedAt: Long = 0, @ColumnInfo(defaultValue = "0") val fetchedAt: Long = 0, @ColumnInfo(defaultValue = "NULL") val number: Double? = null, @ColumnInfo(defaultValue = "NULL") val season: Int? = null, @ColumnInfo(defaultValue = "NULL") val numberingName: String? = null, @ColumnInfo(defaultValue = "NULL") val fillerOverride: Boolean? = null, ) @Entity(tableName = "category") data class CategoryRow( @PrimaryKey val id: Long, val name: String, val forItemType: String, val position: Int? = null, val hidden: Boolean? = null, val shouldUpdate: Boolean? = null, val updatedAt: Long = 0, ) @Entity(tableName = "source") data class SourceRow( @PrimaryKey val id: Long, val name: String = "", val baseUrl: String = "", val lang: String = "", val isActive: Boolean = true, val isAdded: Boolean = false, val isPinned: Boolean = false, val isNsfw: Boolean = false, val sourceCode: String = "", val sourceCodeUrl: String = "", val typeSource: String = "", val iconUrl: String = "", val isFullData: Boolean = false, val hasCloudflare: Boolean = false, val lastUsed: Boolean = false, val dateFormat: String = "", val dateFormatLocale: String = "", val apiUrl: String = "", val version: String = "0.0.1", val versionLast: String = "0.0.1", val headers: String = "", val supportLatest: Boolean? = null, val filterList: String? = null, val preferenceList: String? = null, val itemType: String, val appMinVerReq: String = "", val additionalParams: String = "", val isLocal: Boolean = false, val isObsolete: Boolean = false, val sourceCodeLanguage: String, val notes: String = "", val repoJson: String? = null, val updatedAt: Long = 0, ) @Entity(tableName = "history") data class HistoryRow( @PrimaryKey val id: Long, val mangaId: Long? = null, val chapterId: Long? = null, val itemType: String, val date: String? = null, val updatedAt: Long = 0, val readingTimeSeconds: Int? = null, ) @Entity(tableName = "library_update") data class UpdateRow( @PrimaryKey val id: Long, val mangaId: Long? = null, val chapterId: Long? = null, val chapterName: String? = null, val date: String? = null, val updatedAt: Long = 0, ) @Entity(tableName = "download") data class DownloadRow( @PrimaryKey val id: Long, val chapterId: Long? = null, val succeeded: Int? = null, val failed: Int? = null, val total: Int? = null, val isDownload: Boolean? = null, val isStartDownload: Boolean? = null, @ColumnInfo(defaultValue = "0") val isPaused: Boolean = false, val storageLocation: String? = null, val requestJson: String? = null, ) @Entity(tableName = "track") data class TrackRow( @PrimaryKey val id: Long, val libraryId: Long? = null, val mediaId: Long? = null, val mangaId: Long? = null, val syncId: Int? = null, val title: String? = null, val lastChapterRead: Int? = null, val totalChapter: Int? = null, val score: Int? = null, val status: String, val startedReadingDate: Long? = null, val finishedReadingDate: Long? = null, val trackingUrl: String? = null, val itemType: String, val updatedAt: Long = 0, ) @Entity(tableName = "track_preference") data class TrackPreferenceRow( @PrimaryKey val syncId: Long, val username: String? = null, val oauth: String? = null, val prefs: String? = null, val refreshing: Boolean? = null, ) @Entity(tableName = "track_search") data class TrackSearchRow( @PrimaryKey(autoGenerate = true) val rowId: Long = 0, val id: Long? = null, val libraryId: Long? = null, val mediaId: Long? = null, val syncId: Int? = null, val title: String? = null, val lastChapterRead: Int? = null, val totalChapter: Int? = null, val score: Double? = null, val status: String = "", val startedReadingDate: Long? = null, val finishedReadingDate: Long? = null, val trackingUrl: String? = null, val coverUrl: String = "", val summary: String = "", val publishingStatus: String = "", val publishingType: String = "", val startDate: String = "", ) @Entity(tableName = "sync_preference") data class SyncPreferenceRow( @PrimaryKey val syncId: Long, val email: String? = null, val authToken: String? = null, val lastSyncManga: Long? = null, val lastSyncHistory: Long? = null, val lastSyncUpdate: Long? = null, val server: String? = null, val syncOn: Boolean = false, val autoSyncFrequency: Int = 0, val syncHistories: Boolean = false, val syncUpdates: Boolean = false, val syncSettings: Boolean = false, @ColumnInfo(defaultValue = "0") val hubHead: Long = 0, @ColumnInfo(defaultValue = "0") val hubEpoch: Int = 0, @ColumnInfo(defaultValue = "0") val hubRecoveryPending: Boolean = false, @ColumnInfo(defaultValue = "1") val hubBootstrapComplete: Boolean = false, @ColumnInfo(defaultValue = "0") val hubHlc: Long = 0, val deviceId: String? = null, @ColumnInfo(defaultValue = "'YokanHub'") val serverProvider: String = "YokanHub", val mangayomiIdMappings: String? = null, ) @Entity(tableName = "changed_part") data class ChangedPartRow( @PrimaryKey val id: Long, val actionType: String, val isarId: Long? = null, val data: String, val clientDate: Long, ) /** Unpushed hub ops; see `DbOutboxOp`. */ @Entity(tableName = "outbox", primaryKeys = ["kind", "id", "path"]) data class OutboxRow( val kind: Int, val id: Long, val path: String, val value: String? = null, val hlc: Long, val seq: Long, @ColumnInfo(defaultValue = "0") val epoch: Int = 0, ) @Entity(tableName = "custom_button") data class CustomButtonRow( @PrimaryKey val id: Long, val title: String? = null, val codePress: String? = null, val codeLongPress: String = "", val codeStartup: String = "", val isFavourite: Boolean = false, val position: Int, val updatedAt: Long = 0, ) @Entity(tableName = "page_cache") data class PageCacheRow( @PrimaryKey val chapterId: Long, val chapterUrl: String? = null, val urls: String? = null, val headers: String? = null, val fetchedAt: Long? = null, val sourceId: Long? = null, val sourceVersion: String? = null, ) /** Single-row settings table; payload is the whole DbSettings serialized to JSON. */ @Entity(tableName = "settings") data class SettingsRow( @PrimaryKey val id: Long = 1L, val json: String, ) /** Durable host-owned recipe catalog checkpoint. These rows are intentionally excluded from legacy snapshots. */ @Entity(tableName = "recipe_catalog_checkpoint") data class RecipeCatalogCheckpointRow( @PrimaryKey val catalogId: String, val generation: Long, val replayRevision: Long? = null, val replayPayloadHash: ByteArray? = null, ) @Entity(tableName = "recipe_catalog_trust_key", primaryKeys = ["catalogId", "keyId"]) data class RecipeCatalogTrustKeyRow( val catalogId: String, val keyId: String, val rawEd25519PublicKey: ByteArray, val state: String, val validFromEpochSeconds: Long? = null, val validUntilEpochSeconds: Long? = null, ) @Entity(tableName = "recipe_catalog_installed", primaryKeys = ["catalogId", "stableId"]) data class RecipeCatalogInstalledRow( val catalogId: String, val stableId: String, val catalogRevision: Long, val releaseVersion: String, val sha256: String, val sizeBytes: Long, val artifactBytes: ByteArray, /** Host-owned source row identity; null is a v6 record awaiting lazy materialization. */ val sourceId: Long? = null, ) // ─── DAOs ─────────────────────────────────────────────────────────────────── // Each DAO exposes only `all()` / `upsert()` / `delete()` / `clear()`. Reads // are still served from the in-memory snapshot for synchronous access; the // DAOs only run on startup (hydration) and on mutations (write-through). @Dao interface MangaDao { @Query("SELECT * FROM manga") suspend fun all(): List @Upsert suspend fun upsert(row: MangaRow) @Upsert suspend fun upsertAll(rows: List) @Query("DELETE FROM manga") suspend fun clear() @Query("DELETE FROM manga WHERE id = :id") suspend fun delete(id: Long) } @Dao interface ChapterDao { @Query("SELECT * FROM chapter") suspend fun all(): List @Upsert suspend fun upsert(row: ChapterRow) @Upsert suspend fun upsertAll(rows: List) @Query("DELETE FROM chapter") suspend fun clear() @Query("DELETE FROM chapter WHERE id = :id") suspend fun delete(id: Long) } @Dao interface CategoryDao { @Query("SELECT * FROM category") suspend fun all(): List @Upsert suspend fun upsert(row: CategoryRow) @Upsert suspend fun upsertAll(rows: List) @Query("DELETE FROM category") suspend fun clear() @Query("DELETE FROM category WHERE id = :id") suspend fun delete(id: Long) } @Dao interface SourceDao { @Query("SELECT * FROM source") suspend fun all(): List @Query("SELECT * FROM source WHERE id = :id") suspend fun source(id: Long): SourceRow? @Upsert suspend fun upsert(row: SourceRow) @Upsert suspend fun upsertAll(rows: List) @Query("DELETE FROM source") suspend fun clear() @Query("DELETE FROM source WHERE id = :id") suspend fun delete(id: Long) } @Dao interface HistoryDao { @Query("SELECT * FROM history") suspend fun all(): List @Upsert suspend fun upsert(row: HistoryRow) @Upsert suspend fun upsertAll(rows: List) @Query("DELETE FROM history") suspend fun clear() @Query("DELETE FROM history WHERE id = :id") suspend fun delete(id: Long) } @Dao interface UpdateDao { @Query("SELECT * FROM library_update") suspend fun all(): List @Upsert suspend fun upsert(row: UpdateRow) @Upsert suspend fun upsertAll(rows: List) @Query("DELETE FROM library_update") suspend fun clear() @Query("DELETE FROM library_update WHERE id = :id") suspend fun delete(id: Long) } @Dao interface DownloadDao { @Query("SELECT * FROM download") suspend fun all(): List @Upsert suspend fun upsert(row: DownloadRow) @Upsert suspend fun upsertAll(rows: List) @Query("DELETE FROM download") suspend fun clear() @Query("DELETE FROM download WHERE id = :id") suspend fun delete(id: Long) } @Dao interface TrackDao { @Query("SELECT * FROM track") suspend fun all(): List @Upsert suspend fun upsert(row: TrackRow) @Upsert suspend fun upsertAll(rows: List) @Query("DELETE FROM track") suspend fun clear() @Query("DELETE FROM track WHERE id = :id") suspend fun delete(id: Long) } @Dao interface TrackPreferenceDao { @Query("SELECT * FROM track_preference") suspend fun all(): List @Upsert suspend fun upsert(row: TrackPreferenceRow) @Upsert suspend fun upsertAll(rows: List) @Query("DELETE FROM track_preference") suspend fun clear() } @Dao interface TrackSearchDao { @Query("SELECT * FROM track_search") suspend fun all(): List @Upsert suspend fun upsert(row: TrackSearchRow) @Upsert suspend fun upsertAll(rows: List) @Query("DELETE FROM track_search") suspend fun clear() } @Dao interface SyncPreferenceDao { @Query("SELECT * FROM sync_preference") suspend fun all(): List @Upsert suspend fun upsert(row: SyncPreferenceRow) @Upsert suspend fun upsertAll(rows: List) @Query("DELETE FROM sync_preference") suspend fun clear() } @Dao interface ChangedPartDao { @Query("SELECT * FROM changed_part") suspend fun all(): List @Upsert suspend fun upsert(row: ChangedPartRow) @Upsert suspend fun upsertAll(rows: List) @Query("DELETE FROM changed_part") suspend fun clear() } @Dao interface OutboxDao { @Query("SELECT * FROM outbox") suspend fun all(): List @Upsert suspend fun upsertAll(rows: List) @Query("DELETE FROM outbox WHERE kind = :kind AND id = :id AND path = :path AND seq = :seq") suspend fun deleteIfUnchanged(kind: Int, id: Long, path: String, seq: Long) @Query("DELETE FROM outbox") suspend fun clear() @Query("DELETE FROM outbox WHERE epoch = 0") suspend fun clearUnnegotiated() } @Dao interface CustomButtonDao { @Query("SELECT * FROM custom_button") suspend fun all(): List @Upsert suspend fun upsert(row: CustomButtonRow) @Upsert suspend fun upsertAll(rows: List) @Query("DELETE FROM custom_button") suspend fun clear() @Query("DELETE FROM custom_button WHERE id = :id") suspend fun delete(id: Long) } @Dao interface PageCacheDao { @Query("SELECT * FROM page_cache") suspend fun all(): List @Upsert suspend fun upsert(row: PageCacheRow) @Upsert suspend fun upsertAll(rows: List) @Query("DELETE FROM page_cache") suspend fun clear() @Query("DELETE FROM page_cache WHERE chapterId = :chapterId") suspend fun delete(chapterId: Long) } @Dao interface SettingsDao { @Query("SELECT * FROM settings WHERE id = 1") suspend fun get(): SettingsRow? @Upsert suspend fun upsert(row: SettingsRow) } @Dao interface RecipeInstallationDao { @Query("SELECT * FROM recipe_catalog_checkpoint WHERE catalogId = :catalogId") suspend fun checkpoint(catalogId: String): RecipeCatalogCheckpointRow? @Query("SELECT * FROM recipe_catalog_checkpoint") suspend fun allCheckpoints(): List @Query("SELECT * FROM recipe_catalog_trust_key WHERE catalogId = :catalogId ORDER BY keyId") suspend fun trustKeys(catalogId: String): List @Query("SELECT * FROM recipe_catalog_installed WHERE catalogId = :catalogId ORDER BY stableId") suspend fun installed(catalogId: String): List @Query("SELECT * FROM recipe_catalog_installed ORDER BY catalogId, stableId") suspend fun allInstalled(): List @Insert(onConflict = OnConflictStrategy.IGNORE) suspend fun insertCheckpoint(row: RecipeCatalogCheckpointRow): Long @Insert(onConflict = OnConflictStrategy.ABORT) suspend fun insertTrustKeys(rows: List) @Upsert suspend fun upsertCheckpoint(row: RecipeCatalogCheckpointRow) @Upsert suspend fun upsertInstalled(row: RecipeCatalogInstalledRow) @Query("DELETE FROM recipe_catalog_installed WHERE catalogId = :catalogId AND stableId = :stableId") suspend fun deleteInstalled(catalogId: String, stableId: String) @Query("DELETE FROM recipe_catalog_trust_key WHERE catalogId = :catalogId") suspend fun deleteTrustKeys(catalogId: String) } @Database( entities = [ MangaRow::class, MangaCreditRow::class, ChapterRow::class, CategoryRow::class, SourceRow::class, HistoryRow::class, UpdateRow::class, DownloadRow::class, TrackRow::class, TrackPreferenceRow::class, TrackSearchRow::class, SyncPreferenceRow::class, ChangedPartRow::class, CustomButtonRow::class, PageCacheRow::class, SettingsRow::class, OutboxRow::class, RecipeCatalogCheckpointRow::class, RecipeCatalogTrustKeyRow::class, RecipeCatalogInstalledRow::class, ], version = 16, exportSchema = true, ) @ConstructedBy(YokanRoomDatabaseConstructor::class) abstract class YokanRoomDatabase : RoomDatabase() { abstract fun mangaDao(): MangaDao abstract fun mangaCreditDao(): MangaCreditDao abstract fun chapterDao(): ChapterDao abstract fun categoryDao(): CategoryDao abstract fun sourceDao(): SourceDao abstract fun historyDao(): HistoryDao abstract fun updateDao(): UpdateDao abstract fun downloadDao(): DownloadDao abstract fun trackDao(): TrackDao abstract fun trackPreferenceDao(): TrackPreferenceDao abstract fun trackSearchDao(): TrackSearchDao abstract fun syncPreferenceDao(): SyncPreferenceDao abstract fun changedPartDao(): ChangedPartDao abstract fun customButtonDao(): CustomButtonDao abstract fun pageCacheDao(): PageCacheDao abstract fun settingsDao(): SettingsDao abstract fun outboxDao(): OutboxDao abstract fun recipeInstallationDao(): RecipeInstallationDao } /** v1 → v2: hub sync. New `outbox` table, hub cursor columns on `sync_preference`. */ val MIGRATION_1_2: Migration = object : Migration(1, 2) { override fun migrate(connection: SQLiteConnection) { connection.execSQL( "CREATE TABLE IF NOT EXISTS `outbox` (`kind` INTEGER NOT NULL, `id` INTEGER NOT NULL, `path` TEXT NOT NULL, " + "`value` TEXT, `hlc` INTEGER NOT NULL, `seq` INTEGER NOT NULL, PRIMARY KEY(`kind`, `id`, `path`))", ) connection.execSQL("ALTER TABLE `sync_preference` ADD COLUMN `hubHead` INTEGER NOT NULL DEFAULT 0") connection.execSQL("ALTER TABLE `sync_preference` ADD COLUMN `hubEpoch` INTEGER NOT NULL DEFAULT 0") connection.execSQL("ALTER TABLE `sync_preference` ADD COLUMN `hubHlc` INTEGER NOT NULL DEFAULT 0") connection.execSQL("ALTER TABLE `sync_preference` ADD COLUMN `deviceId` TEXT") } } /** v2 → v3: tag outbox operations with the hub history epoch. */ val MIGRATION_2_3: Migration = object : Migration(2, 3) { override fun migrate(connection: SQLiteConnection) { connection.execSQL("ALTER TABLE `outbox` ADD COLUMN `epoch` INTEGER NOT NULL DEFAULT 0") } } /** v3 → v4: persist interrupted hub rollback recovery. */ val MIGRATION_3_4: Migration = object : Migration(3, 4) { override fun migrate(connection: SQLiteConnection) { connection.execSQL("ALTER TABLE `sync_preference` ADD COLUMN `hubRecoveryPending` INTEGER NOT NULL DEFAULT 0") } } /** v4 → v5: persist bootstrap eligibility independently of the hub cursor. */ val MIGRATION_4_5: Migration = object : Migration(4, 5) { override fun migrate(connection: SQLiteConnection) { connection.execSQL("ALTER TABLE `sync_preference` ADD COLUMN `hubBootstrapComplete` INTEGER NOT NULL DEFAULT 1") } } /** v5 → v6: durable, host-owned recipe catalog checkpoints and artifact records. */ val MIGRATION_5_6: Migration = object : Migration(5, 6) { override fun migrate(connection: SQLiteConnection) { connection.execSQL("CREATE TABLE IF NOT EXISTS `recipe_catalog_checkpoint` (`catalogId` TEXT NOT NULL, `generation` INTEGER NOT NULL, `replayRevision` INTEGER, `replayPayloadHash` BLOB, PRIMARY KEY(`catalogId`))") connection.execSQL("CREATE TABLE IF NOT EXISTS `recipe_catalog_trust_key` (`catalogId` TEXT NOT NULL, `keyId` TEXT NOT NULL, `rawEd25519PublicKey` BLOB NOT NULL, `state` TEXT NOT NULL, `validFromEpochSeconds` INTEGER, `validUntilEpochSeconds` INTEGER, PRIMARY KEY(`catalogId`, `keyId`))") connection.execSQL("CREATE TABLE IF NOT EXISTS `recipe_catalog_installed` (`catalogId` TEXT NOT NULL, `stableId` TEXT NOT NULL, `catalogRevision` INTEGER NOT NULL, `releaseVersion` TEXT NOT NULL, `sha256` TEXT NOT NULL, `sizeBytes` INTEGER NOT NULL, `artifactBytes` BLOB NOT NULL, PRIMARY KEY(`catalogId`, `stableId`))") } } /** v6 → v7: bind each signed recipe artifact to a durable, host-owned source row. */ val MIGRATION_6_7: Migration = object : Migration(6, 7) { override fun migrate(connection: SQLiteConnection) { connection.execSQL("ALTER TABLE `recipe_catalog_installed` ADD COLUMN `sourceId` INTEGER") } } /** v7 → v8: page-list freshness. Existing lists get no `fetchedAt`, so they are refetched once. */ val MIGRATION_7_8: Migration = object : Migration(7, 8) { override fun migrate(connection: SQLiteConnection) { connection.execSQL("ALTER TABLE `page_cache` ADD COLUMN `fetchedAt` INTEGER") connection.execSQL("ALTER TABLE `page_cache` ADD COLUMN `sourceId` INTEGER") connection.execSQL("ALTER TABLE `page_cache` ADD COLUMN `sourceVersion` TEXT") } } /** v8 → v9: keep the selected sync server provider independent of its configured URL. */ val MIGRATION_8_9: Migration = object : Migration(8, 9) { override fun migrate(connection: SQLiteConnection) { connection.execSQL("ALTER TABLE `sync_preference` ADD COLUMN `serverProvider` TEXT NOT NULL DEFAULT 'YokanHub'") } } /** v9 → v10: persist stable Mangayomi-safe client IDs. */ val MIGRATION_9_10: Migration = object : Migration(9, 10) { override fun migrate(connection: SQLiteConnection) { connection.execSQL("ALTER TABLE `sync_preference` ADD COLUMN `mangayomiIdMappings` TEXT") } } /** v10 → v11: private title notes, empty for existing libraries. */ val MIGRATION_10_11: Migration = object : Migration(10, 11) { override fun migrate(connection: SQLiteConnection) { connection.execSQL("ALTER TABLE `manga` ADD COLUMN `privateNote` TEXT NOT NULL DEFAULT ''") } } /** v11 → v12: restore pause intent and exact download destinations/options. */ val MIGRATION_11_12: Migration = object : Migration(11, 12) { override fun migrate(connection: SQLiteConnection) { connection.execSQL("ALTER TABLE `download` ADD COLUMN `isPaused` INTEGER NOT NULL DEFAULT 0") connection.execSQL("ALTER TABLE `download` ADD COLUMN `storageLocation` TEXT") connection.execSQL("ALTER TABLE `download` ADD COLUMN `requestJson` TEXT") } } /** v12 → v13: independent chapter discovery timestamps and provider-announced anime schedules. */ val MIGRATION_12_13: Migration = object : Migration(12, 13) { override fun migrate(connection: SQLiteConnection) { connection.execSQL("ALTER TABLE `chapter` ADD COLUMN `fetchedAt` INTEGER NOT NULL DEFAULT 0") connection.execSQL("ALTER TABLE `manga` ADD COLUMN `nextEpisodeAiringAt` INTEGER NOT NULL DEFAULT 0") connection.execSQL("ALTER TABLE `manga` ADD COLUMN `nextEpisodeNumber` INTEGER DEFAULT NULL") connection.execSQL("ALTER TABLE `manga` ADD COLUMN `airingScheduleUpdatedAt` INTEGER NOT NULL DEFAULT 0") } } /** v13 → v14: source numbering independent of optional local episode display titles. */ val MIGRATION_13_14: Migration = object : Migration(13, 14) { override fun migrate(connection: SQLiteConnection) { connection.execSQL("ALTER TABLE `chapter` ADD COLUMN `number` REAL DEFAULT NULL") connection.execSQL("ALTER TABLE `chapter` ADD COLUMN `season` INTEGER DEFAULT NULL") connection.execSQL("ALTER TABLE `chapter` ADD COLUMN `numberingName` TEXT DEFAULT NULL") } } val MIGRATION_14_15: Migration = object : Migration(14, 15) { override fun migrate(connection: SQLiteConnection) { connection.execSQL("CREATE TABLE IF NOT EXISTS `manga_credit` (`mangaId` INTEGER NOT NULL, `position` INTEGER NOT NULL, `name` TEXT NOT NULL, `role` TEXT, `character` TEXT, `imageUrl` TEXT, PRIMARY KEY(`mangaId`, `position`), FOREIGN KEY(`mangaId`) REFERENCES `manga`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE)") } } /** v15 → v16: Animetail season records (parent link, fetch type, season number) and user filler overrides. */ val MIGRATION_15_16: Migration = object : Migration(15, 16) { override fun migrate(connection: SQLiteConnection) { connection.execSQL("ALTER TABLE `manga` ADD COLUMN `parentId` INTEGER DEFAULT NULL") connection.execSQL("ALTER TABLE `manga` ADD COLUMN `fetchType` TEXT NOT NULL DEFAULT 'Episodes'") connection.execSQL("ALTER TABLE `manga` ADD COLUMN `seasonNumber` REAL DEFAULT NULL") connection.execSQL("ALTER TABLE `chapter` ADD COLUMN `fillerOverride` INTEGER DEFAULT NULL") } } @Suppress("KotlinNoActualForExpect") expect object YokanRoomDatabaseConstructor : RoomDatabaseConstructor { override fun initialize(): YokanRoomDatabase } expect fun createYokanRoomDatabase(profileId: eu.friedcutlet.yokan.domain.ProfileId = eu.friedcutlet.yokan.domain.ProfileId.Default): YokanRoomDatabase /** Driver, query lane and full migration chain shared by every [createYokanRoomDatabase] actual. */ internal fun RoomDatabase.Builder.buildYokanRoom(): YokanRoomDatabase = this .setDriver(BundledSQLiteDriver()) .setQueryCoroutineContext(roomPersistenceDispatcher) .addMigrations(MIGRATION_1_2, MIGRATION_2_3, MIGRATION_3_4, MIGRATION_4_5, MIGRATION_5_6, MIGRATION_6_7, MIGRATION_7_8, MIGRATION_8_9, MIGRATION_9_10, MIGRATION_10_11, MIGRATION_11_12, MIGRATION_12_13, MIGRATION_13_14, MIGRATION_14_15, MIGRATION_15_16) .build()