fix: ensure default category
This commit is contained in:
parent
67e5eb8edf
commit
f2b2b04bac
3 changed files with 8 additions and 10 deletions
|
|
@ -49,9 +49,6 @@ object AppModule {
|
|||
@Provides
|
||||
@Singleton
|
||||
fun provideBookDatabase(app: Application): BookDatabase {
|
||||
// Additional Migrations
|
||||
DatabaseHelper.AUTO_MIGRATION_7_8.removeBooksDir(app)
|
||||
|
||||
return Room.databaseBuilder(
|
||||
app,
|
||||
BookDatabase::class.java,
|
||||
|
|
@ -63,6 +60,10 @@ object AppModule {
|
|||
DatabaseHelper.MANUAL_MIGRATION_13_14, // remove nullability from ColorPresetEntity
|
||||
DatabaseHelper.MANUAL_MIGRATION_14_15, // remove author nullability from BookEntity
|
||||
DatabaseHelper.MANUAL_MIGRATION_15_16, // merge CategoryEntity and CategorySortEntity
|
||||
).allowMainThreadQueries().build()
|
||||
).allowMainThreadQueries().build().also { database ->
|
||||
// Additional Migrations
|
||||
DatabaseHelper.AUTO_MIGRATION_7_8.removeBooksDir(app)
|
||||
database.categoryDao.ensureDefaultCategory()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -221,12 +221,6 @@ object DatabaseHelper {
|
|||
ON c.id = cs.categoryId
|
||||
"""
|
||||
)
|
||||
database.execSQL(
|
||||
"""
|
||||
INSERT INTO CategoryEntity_new (id, title, `order`, sortOrder, sortOrderDescending)
|
||||
VALUES (-1, '', -1, 'LAST_READ', 1)
|
||||
"""
|
||||
)
|
||||
database.execSQL("DROP TABLE CategoryEntity")
|
||||
database.execSQL("DROP TABLE CategorySortEntity")
|
||||
database.execSQL("ALTER TABLE CategoryEntity_new RENAME TO CategoryEntity")
|
||||
|
|
|
|||
|
|
@ -16,6 +16,9 @@ import ua.acclorite.book_story.data.local.dto.CategoryEntity
|
|||
|
||||
@Dao
|
||||
interface CategoryDao {
|
||||
@Query("INSERT OR IGNORE INTO CategoryEntity (id, title, `order`, sortOrder, sortOrderDescending) VALUES (-1, '', -1, 'LAST_READ', 1)")
|
||||
fun ensureDefaultCategory()
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun insertCategory(
|
||||
category: CategoryEntity
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue