summaryrefslogtreecommitdiff
path: root/app/src/main/java/org/terst/feedreader/data/AppDatabase.kt
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/org/terst/feedreader/data/AppDatabase.kt')
-rw-r--r--app/src/main/java/org/terst/feedreader/data/AppDatabase.kt17
1 files changed, 15 insertions, 2 deletions
diff --git a/app/src/main/java/org/terst/feedreader/data/AppDatabase.kt b/app/src/main/java/org/terst/feedreader/data/AppDatabase.kt
index 441556b..66722fd 100644
--- a/app/src/main/java/org/terst/feedreader/data/AppDatabase.kt
+++ b/app/src/main/java/org/terst/feedreader/data/AppDatabase.kt
@@ -9,7 +9,7 @@ import androidx.room.migration.Migration
@Database(
entities = [FeedEntity::class, ArticleEntity::class, FilterRuleEntity::class],
- version = 4,
+ version = 5,
exportSchema = false
)
abstract class AppDatabase : RoomDatabase() {
@@ -77,12 +77,25 @@ abstract class AppDatabase : RoomDatabase() {
}
}
+ // v5: a feed with a literal empty <guid>/<id> element (confirmed live: a Mother
+ // Jones entry) produced an ArticleEntity with id = "" -- FeedParser fell back to
+ // itemLink only when the guid was null, not when it was blank. An empty-string
+ // primary key broke Navigation Compose's route matching and crashed on tap. The
+ // parser is fixed for future fetches; this cleans out any row already on-device
+ // with the bad id so it doesn't keep crashing. It'll come back with a real,
+ // hash-based id on the next fetch of that feed.
+ private val MIGRATION_4_5 = object : Migration(4, 5) {
+ override fun migrate(db: SupportSQLiteDatabase) {
+ db.execSQL("DELETE FROM articles WHERE trim(id) = ''")
+ }
+ }
+
fun get(context: Context): AppDatabase = instance ?: synchronized(this) {
instance ?: Room.databaseBuilder(
context.applicationContext,
AppDatabase::class.java,
"feedreader.db"
- ).addMigrations(MIGRATION_1_2, MIGRATION_2_3, MIGRATION_3_4).build().also { instance = it }
+ ).addMigrations(MIGRATION_1_2, MIGRATION_2_3, MIGRATION_3_4, MIGRATION_4_5).build().also { instance = it }
}
}
}