Remove the nullable flag on the lastRead field for Lexicon & Quest
This commit is contained in:
parent
b443b57eec
commit
9f44ce4543
12 changed files with 55 additions and 245 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package com.pixelized.rplexicon.data.database
|
||||
|
||||
import android.content.Context
|
||||
import androidx.room.AutoMigration
|
||||
import androidx.room.Database
|
||||
import androidx.room.Room
|
||||
import androidx.room.RoomDatabase
|
||||
|
|
@ -16,7 +17,7 @@ import dagger.hilt.components.SingletonComponent
|
|||
|
||||
@Database(
|
||||
entities = [LexiconDbo::class, QuestDbo::class],
|
||||
version = 2,
|
||||
version = 1,
|
||||
exportSchema = true,
|
||||
)
|
||||
abstract class CompanionDatabase : RoomDatabase() {
|
||||
|
|
@ -34,7 +35,6 @@ class DatabaseModule {
|
|||
): CompanionDatabase {
|
||||
return synchronized(this) {
|
||||
Room.databaseBuilder(context, CompanionDatabase::class.java, "companion_database")
|
||||
.fallbackToDestructiveMigration()
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,8 +19,8 @@ interface LexiconDao {
|
|||
@Query("SELECT id from lexicon WHERE name = :name LIMIT 1")
|
||||
suspend fun getIdByName(name: String): String?
|
||||
|
||||
@Insert(entity = LexiconDbo::class, onConflict = OnConflictStrategy.IGNORE)
|
||||
fun insert(item: LexiconDataDbo)
|
||||
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
||||
fun insert(item: LexiconDbo)
|
||||
|
||||
@Update(entity = LexiconDbo::class)
|
||||
fun update(item: LexiconDataDbo): Int
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ data class LexiconDbo(
|
|||
val history: String?,
|
||||
val tags: String?,
|
||||
val lastUpdated: Long?,
|
||||
val lastRead: Long?,
|
||||
val lastRead: Long,
|
||||
)
|
||||
|
||||
@Entity(tableName = "lexicon")
|
||||
|
|
@ -38,11 +38,28 @@ data class LexiconDataDbo(
|
|||
val history: String?,
|
||||
val tags: String?,
|
||||
val lastUpdated: Long?,
|
||||
)
|
||||
) {
|
||||
infix fun with(lastRead: Long) = LexiconDbo(
|
||||
id = id,
|
||||
name = name,
|
||||
category = category,
|
||||
diminutive = diminutive,
|
||||
gender = gender,
|
||||
race = race,
|
||||
status = status,
|
||||
location = location,
|
||||
portrait = portrait,
|
||||
description = description,
|
||||
history = history,
|
||||
tags = tags,
|
||||
lastUpdated = lastUpdated,
|
||||
lastRead = lastRead,
|
||||
)
|
||||
}
|
||||
|
||||
@Entity(tableName = "lexicon")
|
||||
data class LexiconReadTimestampDbo(
|
||||
@PrimaryKey
|
||||
val id: String,
|
||||
val lastRead: Long?,
|
||||
val lastRead: Long,
|
||||
)
|
||||
|
|
@ -15,8 +15,8 @@ interface QuestDao {
|
|||
@Query("SELECT * from quest WHERE title IN (SELECT title from quest WHERE id = :id)")
|
||||
fun getByIdFlow(id: String): Flow<List<QuestDbo>>
|
||||
|
||||
@Insert(entity = QuestDbo::class, onConflict = OnConflictStrategy.IGNORE)
|
||||
fun insert(item: QuestDataDbo)
|
||||
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
||||
fun insert(item: QuestDbo)
|
||||
|
||||
@Update(entity = QuestDbo::class)
|
||||
fun update(item: QuestDataDbo): Int
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ data class QuestDbo(
|
|||
val illustrations: String?,
|
||||
val background: String?,
|
||||
val lastUpdated: Long?,
|
||||
val lastRead: Long?,
|
||||
val lastRead: Long,
|
||||
)
|
||||
|
||||
@Entity(tableName = "quest")
|
||||
|
|
@ -38,7 +38,24 @@ data class QuestDataDbo(
|
|||
val illustrations: String?,
|
||||
val background: String?,
|
||||
val lastUpdated: Long?,
|
||||
)
|
||||
) {
|
||||
infix fun with(lastRead: Long) = QuestDbo(
|
||||
id = id,
|
||||
category = category,
|
||||
title = title,
|
||||
subTitle = subTitle,
|
||||
completed = completed,
|
||||
questGiver = questGiver,
|
||||
area = area,
|
||||
groupReward = groupReward,
|
||||
individualReward = individualReward,
|
||||
description = description,
|
||||
illustrations = illustrations,
|
||||
background = background,
|
||||
lastUpdated = lastUpdated,
|
||||
lastRead = lastRead,
|
||||
)
|
||||
}
|
||||
|
||||
@Entity(tableName = "quest")
|
||||
data class QuestsReadTimestampDbo(
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ class LexiconParser @Inject constructor(
|
|||
history = data.history,
|
||||
tags = data.tags,
|
||||
lastUpdated = data.lastUpdated,
|
||||
lastRead = data.lastRead ?: timeParser.parser(BuildConfig.DEFAULT_READ_TIME_STAMP) ?: 0,
|
||||
lastRead = data.lastRead,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ class QuestParser @Inject constructor(
|
|||
id = main.id,
|
||||
category = main.category,
|
||||
title = main.title,
|
||||
lastRead = main.lastRead ?: timeParser.parser(BuildConfig.DEFAULT_READ_TIME_STAMP) ?: 0,
|
||||
lastRead = main.lastRead,
|
||||
entries = entry.value.map { convert(data = it) },
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ class LexiconRepository @Inject constructor(
|
|||
database.lexiconDao().also { dao ->
|
||||
data.forEach {
|
||||
val row = dao.update(item = it)
|
||||
if (row == 0) dao.insert(item = it)
|
||||
if (row == 0) dao.insert(item = it with System.currentTimeMillis())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ class QuestRepository @Inject constructor(
|
|||
val dao = database.questsDao()
|
||||
quests.forEach {
|
||||
val row = dao.update(item = it)
|
||||
if (row == 0) dao.insert(item = it)
|
||||
if (row == 0) dao.insert(item = it with System.currentTimeMillis())
|
||||
}
|
||||
|
||||
lastSuccessFullUpdate = Update.currentTime()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue