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,7 +1,3 @@
|
|||
import java.text.SimpleDateFormat
|
||||
import java.util.Date
|
||||
import java.util.Locale
|
||||
|
||||
plugins {
|
||||
id("com.android.application")
|
||||
id("org.jetbrains.kotlin.android")
|
||||
|
|
@ -70,10 +66,6 @@ android {
|
|||
}
|
||||
}
|
||||
|
||||
buildTypes.onEach {
|
||||
it.buildConfigField("String", "DEFAULT_READ_TIME_STAMP", "\"$defaultReadTimestamp\"")
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
|
|
@ -174,12 +166,6 @@ room {
|
|||
schemaDirectory("$projectDir/schemas")
|
||||
}
|
||||
|
||||
val defaultReadTimestamp: String
|
||||
get() {
|
||||
val formatter = SimpleDateFormat("dd/MM/yyyy HH:mm:ss", Locale.FRANCE)
|
||||
return formatter.format(Date()).toString()
|
||||
}
|
||||
|
||||
val gitBuildNumber: Int
|
||||
get() {
|
||||
val stdout = org.apache.commons.io.output.ByteArrayOutputStream()
|
||||
|
|
|
|||
|
|
@ -2,11 +2,11 @@
|
|||
"formatVersion": 1,
|
||||
"database": {
|
||||
"version": 1,
|
||||
"identityHash": "f2d0339fd127a0e9f6e2e816647d9ea9",
|
||||
"identityHash": "c69ae3b018a2383edc96a92797dfdfd3",
|
||||
"entities": [
|
||||
{
|
||||
"tableName": "lexicon",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `name` TEXT NOT NULL, `category` TEXT, `diminutive` TEXT, `gender` TEXT, `race` TEXT, `status` TEXT, `location` TEXT, `portrait` TEXT, `description` TEXT, `history` TEXT, `tags` TEXT, `lastUpdated` INTEGER, `lastRead` INTEGER, PRIMARY KEY(`id`))",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `name` TEXT NOT NULL, `category` TEXT, `diminutive` TEXT, `gender` TEXT, `race` TEXT, `status` TEXT, `location` TEXT, `portrait` TEXT, `description` TEXT, `history` TEXT, `tags` TEXT, `lastUpdated` INTEGER, `lastRead` INTEGER NOT NULL, PRIMARY KEY(`id`))",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "id",
|
||||
|
|
@ -90,7 +90,7 @@
|
|||
"fieldPath": "lastRead",
|
||||
"columnName": "lastRead",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": false
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
|
|
@ -104,7 +104,7 @@
|
|||
},
|
||||
{
|
||||
"tableName": "quest",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `category` TEXT, `title` TEXT NOT NULL, `subTitle` TEXT, `completed` INTEGER NOT NULL, `questGiver` TEXT, `area` TEXT, `groupReward` TEXT, `individualReward` TEXT, `description` TEXT NOT NULL, `illustrations` TEXT, `background` TEXT, `lastUpdated` INTEGER, `lastRead` INTEGER, PRIMARY KEY(`id`))",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `category` TEXT, `title` TEXT NOT NULL, `subTitle` TEXT, `completed` INTEGER NOT NULL, `questGiver` TEXT, `area` TEXT, `groupReward` TEXT, `individualReward` TEXT, `description` TEXT NOT NULL, `illustrations` TEXT, `background` TEXT, `lastUpdated` INTEGER, `lastRead` INTEGER NOT NULL, PRIMARY KEY(`id`))",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "id",
|
||||
|
|
@ -188,7 +188,7 @@
|
|||
"fieldPath": "lastRead",
|
||||
"columnName": "lastRead",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": false
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
|
|
@ -204,7 +204,7 @@
|
|||
"views": [],
|
||||
"setupQueries": [
|
||||
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
||||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'f2d0339fd127a0e9f6e2e816647d9ea9')"
|
||||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'c69ae3b018a2383edc96a92797dfdfd3')"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
@ -1,210 +0,0 @@
|
|||
{
|
||||
"formatVersion": 1,
|
||||
"database": {
|
||||
"version": 2,
|
||||
"identityHash": "f2d0339fd127a0e9f6e2e816647d9ea9",
|
||||
"entities": [
|
||||
{
|
||||
"tableName": "lexicon",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `name` TEXT NOT NULL, `category` TEXT, `diminutive` TEXT, `gender` TEXT, `race` TEXT, `status` TEXT, `location` TEXT, `portrait` TEXT, `description` TEXT, `history` TEXT, `tags` TEXT, `lastUpdated` INTEGER, `lastRead` INTEGER, PRIMARY KEY(`id`))",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "id",
|
||||
"columnName": "id",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "name",
|
||||
"columnName": "name",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "category",
|
||||
"columnName": "category",
|
||||
"affinity": "TEXT",
|
||||
"notNull": false
|
||||
},
|
||||
{
|
||||
"fieldPath": "diminutive",
|
||||
"columnName": "diminutive",
|
||||
"affinity": "TEXT",
|
||||
"notNull": false
|
||||
},
|
||||
{
|
||||
"fieldPath": "gender",
|
||||
"columnName": "gender",
|
||||
"affinity": "TEXT",
|
||||
"notNull": false
|
||||
},
|
||||
{
|
||||
"fieldPath": "race",
|
||||
"columnName": "race",
|
||||
"affinity": "TEXT",
|
||||
"notNull": false
|
||||
},
|
||||
{
|
||||
"fieldPath": "status",
|
||||
"columnName": "status",
|
||||
"affinity": "TEXT",
|
||||
"notNull": false
|
||||
},
|
||||
{
|
||||
"fieldPath": "location",
|
||||
"columnName": "location",
|
||||
"affinity": "TEXT",
|
||||
"notNull": false
|
||||
},
|
||||
{
|
||||
"fieldPath": "portrait",
|
||||
"columnName": "portrait",
|
||||
"affinity": "TEXT",
|
||||
"notNull": false
|
||||
},
|
||||
{
|
||||
"fieldPath": "description",
|
||||
"columnName": "description",
|
||||
"affinity": "TEXT",
|
||||
"notNull": false
|
||||
},
|
||||
{
|
||||
"fieldPath": "history",
|
||||
"columnName": "history",
|
||||
"affinity": "TEXT",
|
||||
"notNull": false
|
||||
},
|
||||
{
|
||||
"fieldPath": "tags",
|
||||
"columnName": "tags",
|
||||
"affinity": "TEXT",
|
||||
"notNull": false
|
||||
},
|
||||
{
|
||||
"fieldPath": "lastUpdated",
|
||||
"columnName": "lastUpdated",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": false
|
||||
},
|
||||
{
|
||||
"fieldPath": "lastRead",
|
||||
"columnName": "lastRead",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": false
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": false,
|
||||
"columnNames": [
|
||||
"id"
|
||||
]
|
||||
},
|
||||
"indices": [],
|
||||
"foreignKeys": []
|
||||
},
|
||||
{
|
||||
"tableName": "quest",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `category` TEXT, `title` TEXT NOT NULL, `subTitle` TEXT, `completed` INTEGER NOT NULL, `questGiver` TEXT, `area` TEXT, `groupReward` TEXT, `individualReward` TEXT, `description` TEXT NOT NULL, `illustrations` TEXT, `background` TEXT, `lastUpdated` INTEGER, `lastRead` INTEGER, PRIMARY KEY(`id`))",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "id",
|
||||
"columnName": "id",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "category",
|
||||
"columnName": "category",
|
||||
"affinity": "TEXT",
|
||||
"notNull": false
|
||||
},
|
||||
{
|
||||
"fieldPath": "title",
|
||||
"columnName": "title",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "subTitle",
|
||||
"columnName": "subTitle",
|
||||
"affinity": "TEXT",
|
||||
"notNull": false
|
||||
},
|
||||
{
|
||||
"fieldPath": "completed",
|
||||
"columnName": "completed",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "questGiver",
|
||||
"columnName": "questGiver",
|
||||
"affinity": "TEXT",
|
||||
"notNull": false
|
||||
},
|
||||
{
|
||||
"fieldPath": "area",
|
||||
"columnName": "area",
|
||||
"affinity": "TEXT",
|
||||
"notNull": false
|
||||
},
|
||||
{
|
||||
"fieldPath": "groupReward",
|
||||
"columnName": "groupReward",
|
||||
"affinity": "TEXT",
|
||||
"notNull": false
|
||||
},
|
||||
{
|
||||
"fieldPath": "individualReward",
|
||||
"columnName": "individualReward",
|
||||
"affinity": "TEXT",
|
||||
"notNull": false
|
||||
},
|
||||
{
|
||||
"fieldPath": "description",
|
||||
"columnName": "description",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "illustrations",
|
||||
"columnName": "illustrations",
|
||||
"affinity": "TEXT",
|
||||
"notNull": false
|
||||
},
|
||||
{
|
||||
"fieldPath": "background",
|
||||
"columnName": "background",
|
||||
"affinity": "TEXT",
|
||||
"notNull": false
|
||||
},
|
||||
{
|
||||
"fieldPath": "lastUpdated",
|
||||
"columnName": "lastUpdated",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": false
|
||||
},
|
||||
{
|
||||
"fieldPath": "lastRead",
|
||||
"columnName": "lastRead",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": false
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": false,
|
||||
"columnNames": [
|
||||
"id"
|
||||
]
|
||||
},
|
||||
"indices": [],
|
||||
"foreignKeys": []
|
||||
}
|
||||
],
|
||||
"views": [],
|
||||
"setupQueries": [
|
||||
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
||||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'f2d0339fd127a0e9f6e2e816647d9ea9')"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
@ -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