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.kt45
1 files changed, 42 insertions, 3 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 4cf0ecd..441556b 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 = 3,
+ version = 4,
exportSchema = false
)
abstract class AppDatabase : RoomDatabase() {
@@ -31,19 +31,58 @@ abstract class AppDatabase : RoomDatabase() {
}
}
- // v3: added FeedEntity.readerModeDisabled (per-feed reader-mode opt-out).
+ // v3: added FeedEntity.readerModeDisabled (per-feed reader-mode opt-out, paired with
+ // an auto-extract-on-thin-content heuristic). Superseded by v4 below.
private val MIGRATION_2_3 = object : Migration(2, 3) {
override fun migrate(db: SupportSQLiteDatabase) {
db.execSQL("ALTER TABLE feeds ADD COLUMN readerModeDisabled INTEGER NOT NULL DEFAULT 0")
}
}
+ // v4: replaced readerModeDisabled with readerModeEnabled -- reader mode is no longer
+ // ever auto-triggered by a content-length heuristic (that's what kept "auto-switching"
+ // kottke articles even after the v3 opt-out); it's now a plain per-feed opt-in, set
+ // only by explicitly tapping the reader-mode toggle. Starts everyone fresh at off
+ // rather than trying to translate the old opt-out semantics, which don't map cleanly
+ // onto "opt in". A plain ADD COLUMN + leaving the old one in place (as v1->v2 and
+ // v2->v3 do) crashes here: Room's post-migration validation requires the table's
+ // columns to match FeedEntity's fields EXACTLY, and readerModeDisabled isn't a field
+ // anymore -- confirmed live ("Migration didn't properly handle: feeds"). SQLite has no
+ // DROP COLUMN on the versions bundled with older Android, so this rebuilds the table
+ // instead: create with the new shape, copy the columns that still exist, swap in.
+ private val MIGRATION_3_4 = object : Migration(3, 4) {
+ override fun migrate(db: SupportSQLiteDatabase) {
+ db.execSQL(
+ """
+ CREATE TABLE feeds_new (
+ id TEXT NOT NULL PRIMARY KEY,
+ title TEXT NOT NULL,
+ siteUrl TEXT,
+ lastFetchedAt INTEGER,
+ etag TEXT,
+ lastModified TEXT,
+ lastError TEXT,
+ readerModeEnabled INTEGER NOT NULL DEFAULT 0
+ )
+ """.trimIndent()
+ )
+ db.execSQL(
+ """
+ INSERT INTO feeds_new (id, title, siteUrl, lastFetchedAt, etag, lastModified, lastError)
+ SELECT id, title, siteUrl, lastFetchedAt, etag, lastModified, lastError FROM feeds
+ """.trimIndent()
+ )
+ db.execSQL("DROP TABLE feeds")
+ db.execSQL("ALTER TABLE feeds_new RENAME TO feeds")
+ }
+ }
+
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).build().also { instance = it }
+ ).addMigrations(MIGRATION_1_2, MIGRATION_2_3, MIGRATION_3_4).build().also { instance = it }
}
}
}