fix: ensure default category

This commit is contained in:
Acclorite 2025-10-01 13:43:41 +03:00
parent 67e5eb8edf
commit f2b2b04bac
No known key found for this signature in database
GPG key ID: 6E54C611F6EE8593
3 changed files with 8 additions and 10 deletions

View file

@ -49,9 +49,6 @@ object AppModule {
@Provides @Provides
@Singleton @Singleton
fun provideBookDatabase(app: Application): BookDatabase { fun provideBookDatabase(app: Application): BookDatabase {
// Additional Migrations
DatabaseHelper.AUTO_MIGRATION_7_8.removeBooksDir(app)
return Room.databaseBuilder( return Room.databaseBuilder(
app, app,
BookDatabase::class.java, BookDatabase::class.java,
@ -63,6 +60,10 @@ object AppModule {
DatabaseHelper.MANUAL_MIGRATION_13_14, // remove nullability from ColorPresetEntity DatabaseHelper.MANUAL_MIGRATION_13_14, // remove nullability from ColorPresetEntity
DatabaseHelper.MANUAL_MIGRATION_14_15, // remove author nullability from BookEntity DatabaseHelper.MANUAL_MIGRATION_14_15, // remove author nullability from BookEntity
DatabaseHelper.MANUAL_MIGRATION_15_16, // merge CategoryEntity and CategorySortEntity 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()
}
} }
} }

View file

@ -221,12 +221,6 @@ object DatabaseHelper {
ON c.id = cs.categoryId 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 CategoryEntity")
database.execSQL("DROP TABLE CategorySortEntity") database.execSQL("DROP TABLE CategorySortEntity")
database.execSQL("ALTER TABLE CategoryEntity_new RENAME TO CategoryEntity") database.execSQL("ALTER TABLE CategoryEntity_new RENAME TO CategoryEntity")

View file

@ -16,6 +16,9 @@ import ua.acclorite.book_story.data.local.dto.CategoryEntity
@Dao @Dao
interface CategoryDao { 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) @Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertCategory( suspend fun insertCategory(
category: CategoryEntity category: CategoryEntity