refactor: book entity
* Remove nullability from author
This commit is contained in:
parent
56b5aba67a
commit
1d9f5514ff
5 changed files with 260 additions and 6 deletions
|
|
@ -61,6 +61,7 @@ object AppModule {
|
|||
DatabaseHelper.MIGRATION_4_5, // creates ColorPresetEntity table(if does not exist)
|
||||
DatabaseHelper.MIGRATION_5_6, // creates FavoriteDirectoryEntity table(if does not exist)
|
||||
DatabaseHelper.MIGRATION_13_14, // remove nullability from ColorPresetEntity
|
||||
DatabaseHelper.MIGRATION_14_15, // remove author nullability from BookEntity
|
||||
).allowMainThreadQueries().build()
|
||||
}
|
||||
}
|
||||
|
|
@ -17,7 +17,7 @@ import ua.acclorite.book_story.data.converter.CategoryConverter
|
|||
data class BookEntity(
|
||||
@PrimaryKey(true) val id: Int = 0,
|
||||
val title: String,
|
||||
val author: String?,
|
||||
val author: String,
|
||||
val description: String?,
|
||||
val filePath: String,
|
||||
val scrollIndex: Int,
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ import java.io.File
|
|||
CategoryEntity::class,
|
||||
CategorySortEntity::class
|
||||
],
|
||||
version = 14,
|
||||
version = 15,
|
||||
autoMigrations = [
|
||||
AutoMigration(1, 2),
|
||||
AutoMigration(2, 3),
|
||||
|
|
@ -45,6 +45,7 @@ import java.io.File
|
|||
AutoMigration(11, 12),
|
||||
AutoMigration(12, 13),
|
||||
AutoMigration(13, 14),
|
||||
AutoMigration(14, 15),
|
||||
],
|
||||
exportSchema = true
|
||||
)
|
||||
|
|
@ -159,4 +160,34 @@ object DatabaseHelper {
|
|||
database.execSQL("ALTER TABLE ColorPresetEntity_new RENAME TO ColorPresetEntity")
|
||||
}
|
||||
}
|
||||
|
||||
val MIGRATION_14_15 = object : Migration(14, 15) {
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL(
|
||||
"""
|
||||
CREATE TABLE BookEntity_new (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
title TEXT NOT NULL,
|
||||
author TEXT NOT NULL,
|
||||
description TEXT,
|
||||
filePath TEXT NOT NULL,
|
||||
scrollIndex INTEGER NOT NULL,
|
||||
scrollOffset INTEGER NOT NULL,
|
||||
progress REAL NOT NULL,
|
||||
image TEXT,
|
||||
categories TEXT NOT NULL DEFAULT '[]'
|
||||
)
|
||||
"""
|
||||
)
|
||||
database.execSQL(
|
||||
"""
|
||||
INSERT INTO BookEntity_new (id, title, author, description, filePath, scrollIndex, scrollOffset, progress, image, categories)
|
||||
SELECT id, title, COALESCE(author, ''), description, filePath, scrollIndex, scrollOffset, progress, image, categories
|
||||
FROM BookEntity
|
||||
"""
|
||||
)
|
||||
database.execSQL("DROP TABLE BookEntity")
|
||||
database.execSQL("ALTER TABLE BookEntity_new RENAME TO BookEntity")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -22,7 +22,7 @@ class BookMapperImpl @Inject constructor() : BookMapper {
|
|||
scrollIndex = book.scrollIndex,
|
||||
scrollOffset = book.scrollOffset,
|
||||
progress = book.progress,
|
||||
author = book.author.getAsString(),
|
||||
author = book.author.getAsString() ?: "",
|
||||
description = book.description,
|
||||
image = book.coverImage?.toString(),
|
||||
categories = book.categories
|
||||
|
|
@ -33,9 +33,10 @@ class BookMapperImpl @Inject constructor() : BookMapper {
|
|||
return Book(
|
||||
id = bookEntity.id,
|
||||
title = bookEntity.title,
|
||||
author = bookEntity.author?.let { UIText.StringValue(it) } ?: UIText.StringResource(
|
||||
R.string.unknown_author
|
||||
),
|
||||
author = bookEntity.author.let { author ->
|
||||
if (author.isNotBlank()) UIText.StringValue(author)
|
||||
else UIText.StringResource(R.string.unknown_author)
|
||||
},
|
||||
description = bookEntity.description,
|
||||
scrollIndex = bookEntity.scrollIndex,
|
||||
scrollOffset = bookEntity.scrollOffset,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue