Skip to content

StreamVault is a TV-first free IPTV player for Android TV built with Kotlin, Jetpack Compose, Room, Hilt, and Media3.

feat(migration): implement Stalker live-category retry table and update migration paths to v81

David Nashash950ea54bc312
diff --git a/data/schemas/com.streamvault.data.local.StreamVaultDatabase/80.json b/data/schemas/com.streamvault.data.local.StreamVaultDatabase/80.json
index 1153b4b6..3f07a10c 100644
--- a/data/schemas/com.streamvault.data.local.StreamVaultDatabase/80.json
+++ b/data/schemas/com.streamvault.data.local.StreamVaultDatabase/80.json
@@ -2,7 +2,7 @@
"formatVersion": 1,
"database": {
"version": 80,
- "identityHash": "4c7a70bfc0d581d4c86dfa31d69b3de6",
+ "identityHash": "bf6f92b8689ef564643e5c397acc582f",
"entities": [
{
"tableName": "providers",
@@ -5665,84 +5665,6 @@
}
]
},
- {
- "tableName": "stalker_live_category_retries",
- "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`provider_id` INTEGER NOT NULL, `category_id` INTEGER NOT NULL, `category_name` TEXT NOT NULL, `configuration_generation` INTEGER NOT NULL, `attempt_count` INTEGER NOT NULL, `last_attempt_at` INTEGER NOT NULL, `last_error` TEXT, PRIMARY KEY(`provider_id`, `category_id`), FOREIGN KEY(`provider_id`) REFERENCES `providers`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
- "fields": [
- {
- "fieldPath": "providerId",
- "columnName": "provider_id",
- "affinity": "INTEGER",
- "notNull": true
- },
- {
- "fieldPath": "categoryId",
- "columnName": "category_id",
- "affinity": "INTEGER",
- "notNull": true
- },
- {
- "fieldPath": "categoryName",
- "columnName": "category_name",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "configurationGeneration",
- "columnName": "configuration_generation",
- "affinity": "INTEGER",
- "notNull": true
- },
- {
- "fieldPath": "attemptCount",
- "columnName": "attempt_count",
- "affinity": "INTEGER",
- "notNull": true
- },
- {
- "fieldPath": "lastAttemptAt",
- "columnName": "last_attempt_at",
- "affinity": "INTEGER",
- "notNull": true
- },
- {
- "fieldPath": "lastError",
- "columnName": "last_error",
- "affinity": "TEXT"
- }
- ],
- "primaryKey": {
- "autoGenerate": false,
- "columnNames": [
- "provider_id",
- "category_id"
- ]
- },
- "indices": [
- {
- "name": "index_stalker_live_category_retries_provider_id",
- "unique": false,
- "columnNames": [
- "provider_id"
- ],
- "orders": [],
- "createSql": "CREATE INDEX IF NOT EXISTS `index_stalker_live_category_retries_provider_id` ON `${TABLE_NAME}` (`provider_id`)"
- }
- ],
- "foreignKeys": [
- {
- "table": "providers",
- "onDelete": "CASCADE",
- "onUpdate": "NO ACTION",
- "columns": [
- "provider_id"
- ],
- "referencedColumns": [
- "id"
- ]
- }
- ]
- },
{
"tableName": "stalker_portal_state",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`provider_id` INTEGER NOT NULL, `working_endpoint` TEXT, `bootstrap_recipe` TEXT, `bulk_live_supported` INTEGER, `bulk_live_category_fidelity` INTEGER, `movie_wildcard_supported` INTEGER, `series_wildcard_supported` INTEGER, `epg_supported` INTEGER, `safe_metadata_concurrency` INTEGER NOT NULL, `stress_cooldown_until` INTEGER NOT NULL, `endpoint_health_json` TEXT NOT NULL, `endpoint_failed_until` INTEGER NOT NULL, `validated_at` INTEGER NOT NULL, `schema_version` INTEGER NOT NULL, `configuration_generation` INTEGER NOT NULL, `learning_json` TEXT NOT NULL, `observation_source` TEXT NOT NULL, `observed_at` INTEGER NOT NULL, PRIMARY KEY(`provider_id`), FOREIGN KEY(`provider_id`) REFERENCES `providers`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
@@ -7194,7 +7116,7 @@
],
"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, '4c7a70bfc0d581d4c86dfa31d69b3de6')"
+ "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'bf6f92b8689ef564643e5c397acc582f')"
]
}
}
\ No newline at end of file
diff --git a/data/src/androidTest/java/com/streamvault/data/local/StreamVaultDatabaseMigrationTest.kt b/data/src/androidTest/java/com/streamvault/data/local/StreamVaultDatabaseMigrationTest.kt
index 1c17ae8b..b088a681 100644
--- a/data/src/androidTest/java/com/streamvault/data/local/StreamVaultDatabaseMigrationTest.kt
+++ b/data/src/androidTest/java/com/streamvault/data/local/StreamVaultDatabaseMigrationTest.kt
@@ -1979,8 +1979,8 @@ class StreamVaultDatabaseMigrationTest {
}
@Test
- fun migrate78To80_preservesSavedImportWithoutGrantingCompletionProof() {
- val name = "streamvault-78-80-live-receipt"
+ fun migrate78To81_preservesSavedImportWithoutGrantingCompletionProof() {
+ val name = "streamvault-78-81-live-receipt"
migrationTestHelper.createDatabase(name, 78).apply {
execSQL("INSERT INTO providers (id,name,type,is_active,status,last_synced_at,created_at) " +
"VALUES (1,'Synthetic','XTREAM_CODES',1,'UNKNOWN',0,0)")
@@ -2011,6 +2011,62 @@ class StreamVaultDatabaseMigrationTest {
""".trimIndent()))
assertEquals(0, countRows(migrated, "SELECT COUNT(*) FROM pragma_foreign_key_check"))
migrated.close()
+
+ val current = migrationTestHelper.runMigrationsAndValidate(
+ name,
+ 81,
+ true,
+ StreamVaultDatabase.MIGRATION_80_81
+ )
+ assertEquals(1, countRows(current, "SELECT COUNT(*) FROM providers WHERE id=1 AND name='Synthetic'"))
+ assertEquals(1, countRows(current, """
+ SELECT COUNT(*) FROM xtream_live_onboarding_state WHERE provider_id=1
+ AND staged_session_id=123 AND accepted_row_count=7 AND phase='STAGED'
+ AND sealed_session_id IS NULL AND sealed_row_count=0
+ AND sealed_configuration_generation IS NULL AND sealed_mapping_profile IS NULL
+ """.trimIndent()))
+ assertEquals(1, countRows(current, "SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name='stalker_live_category_retries'"))
+ assertEquals(0, countRows(current, "SELECT COUNT(*) FROM pragma_foreign_key_check"))
+ current.close()
+ }
+
+ @Test
+ fun migrate80To81_createsStalkerRetriesAndPreservesHydratedEpisodes() {
+ val name = "streamvault-80-81-stalker-retries"
+ migrationTestHelper.createDatabase(name, 80).apply {
+ insertProvider78(1, "Stalker", "STALKER_PORTAL")
+ insertSeries78(id = 30, seriesId = 3001, providerId = 1, name = "First Series", detailHydratedAt = 555)
+ insertSeries78(id = 31, seriesId = 3002, providerId = 1, name = "Second Series", detailHydratedAt = 666)
+ insertEpisode78(id = 40, episodeId = 10001, seriesId = 30, providerId = 1, title = "First S01E01")
+ insertEpisode78(id = 41, episodeId = 10001, seriesId = 31, providerId = 1, title = "Second S01E01")
+ assertEquals(0, countRows(this, "SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name='stalker_live_category_retries'"))
+ close()
+ }
+
+ val migrated = migrationTestHelper.runMigrationsAndValidate(
+ name,
+ 81,
+ true,
+ StreamVaultDatabase.MIGRATION_80_81
+ )
+ assertEquals(2, countRows(migrated, "SELECT COUNT(*) FROM episodes WHERE provider_id=1 AND episode_id=10001"))
+ assertEquals(1, countRows(migrated, "SELECT COUNT(*) FROM series WHERE id=30 AND detail_hydrated_at=555"))
+ assertEquals(1, countRows(migrated, "SELECT COUNT(*) FROM series WHERE id=31 AND detail_hydrated_at=666"))
+ assertEquals(1, countRows(migrated, "SELECT COUNT(*) FROM pragma_index_list('stalker_live_category_retries') WHERE name='index_stalker_live_category_retries_provider_id'"))
+ assertEquals(1, countRows(migrated, "SELECT COUNT(*) FROM pragma_foreign_key_list('stalker_live_category_retries') WHERE `table`='providers' AND on_delete='CASCADE'"))
+ migrated.execSQL("""
+ INSERT INTO stalker_live_category_retries (
+ provider_id, category_id, category_name, configuration_generation,
+ attempt_count, last_attempt_at, last_error
+ ) VALUES (1, 7, 'News', 3, 2, 100, 'Retryable failure')
+ """.trimIndent())
+ assertEquals(1, countRows(migrated, "SELECT COUNT(*) FROM stalker_live_category_retries WHERE provider_id=1 AND category_id=7"))
+ assertEquals(0, countRows(migrated, "SELECT COUNT(*) FROM pragma_foreign_key_check"))
+ migrated.setForeignKeyConstraintsEnabled(true)
+ migrated.execSQL("DELETE FROM providers WHERE id=1")
+ assertEquals(0, countRows(migrated, "SELECT COUNT(*) FROM stalker_live_category_retries"))
+ assertEquals(0, countRows(migrated, "SELECT COUNT(*) FROM pragma_foreign_key_check"))
+ migrated.close()
}
@Test
diff --git a/data/src/main/java/com/streamvault/data/local/FeatureMigrationsV79To80.kt b/data/src/main/java/com/streamvault/data/local/FeatureMigrationsV79To80.kt
index 485f3ff9..2a37d27b 100644
--- a/data/src/main/java/com/streamvault/data/local/FeatureMigrationsV79To80.kt
+++ b/data/src/main/java/com/streamvault/data/local/FeatureMigrationsV79To80.kt
@@ -25,26 +25,6 @@ internal object FeatureMigrationsV79To80 {
if ("sealed_mapping_profile" !in columns) {
db.execSQL("ALTER TABLE xtream_live_onboarding_state ADD COLUMN sealed_mapping_profile TEXT")
}
-
- db.execSQL(
- """
- CREATE TABLE IF NOT EXISTS `stalker_live_category_retries` (
- `provider_id` INTEGER NOT NULL,
- `category_id` INTEGER NOT NULL,
- `category_name` TEXT NOT NULL,
- `configuration_generation` INTEGER NOT NULL,
- `attempt_count` INTEGER NOT NULL,
- `last_attempt_at` INTEGER NOT NULL,
- `last_error` TEXT,
- PRIMARY KEY(`provider_id`, `category_id`),
- FOREIGN KEY(`provider_id`) REFERENCES `providers`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE
- )
- """.trimIndent()
- )
- db.execSQL(
- "CREATE INDEX IF NOT EXISTS `index_stalker_live_category_retries_provider_id` " +
- "ON `stalker_live_category_retries` (`provider_id`)"
- )
}
}
}
diff --git a/data/src/main/java/com/streamvault/data/local/FeatureMigrationsV80To81.kt b/data/src/main/java/com/streamvault/data/local/FeatureMigrationsV80To81.kt
index 8350216f..f354e85c 100644
--- a/data/src/main/java/com/streamvault/data/local/FeatureMigrationsV80To81.kt
+++ b/data/src/main/java/com/streamvault/data/local/FeatureMigrationsV80To81.kt
@@ -3,16 +3,29 @@ package com.streamvault.data.local
import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase
-/** Repairs episode uniqueness for databases that reached v80 before the fix was added. */
+/** Durable Stalker live-category retry scopes survive process death and provider refreshes. */
internal object FeatureMigrationsV80To81 {
val MIGRATION_80_81 = object : Migration(80, 81) {
override fun migrate(db: SupportSQLiteDatabase) {
- db.execSQL("DROP INDEX IF EXISTS index_episodes_provider_id_episode_id")
db.execSQL(
- "CREATE UNIQUE INDEX IF NOT EXISTS index_episodes_provider_id_series_id_episode_id " +
- "ON episodes(provider_id, series_id, episode_id)"
+ """
+ CREATE TABLE IF NOT EXISTS `stalker_live_category_retries` (
+ `provider_id` INTEGER NOT NULL,
+ `category_id` INTEGER NOT NULL,
+ `category_name` TEXT NOT NULL,
+ `configuration_generation` INTEGER NOT NULL,
+ `attempt_count` INTEGER NOT NULL,
+ `last_attempt_at` INTEGER NOT NULL,
+ `last_error` TEXT,
+ PRIMARY KEY(`provider_id`, `category_id`),
+ FOREIGN KEY(`provider_id`) REFERENCES `providers`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE
+ )
+ """.trimIndent()
+ )
+ db.execSQL(
+ "CREATE INDEX IF NOT EXISTS `index_stalker_live_category_retries_provider_id` " +
+ "ON `stalker_live_category_retries` (`provider_id`)"
)
- db.execSQL("UPDATE series SET detail_hydrated_at = 1 WHERE detail_hydrated_at > 0")
}
}
}
diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md
index 11056c55..eed92e2f 100644
--- a/docs/CHANGELOG.md
+++ b/docs/CHANGELOG.md
@@ -2,12 +2,6 @@
All notable product changes are recorded in this document.
-## [Unreleased]
-
-### Fixed
-
-- Fixed Xtream series losing some or all of their episodes after another series was opened (#166). Episode ids are now unique per series instead of per provider, and series cached before the fix are re-fetched the next time they are opened.
-
## [1.2.0]
### Added
@@ -29,6 +23,8 @@ All notable product changes are recorded in this document.
- Fixed Xtream playlist setup ignoring the requested HLS or MPEG-TS format when playback format is set to Auto.
- Fixed matching AVC/H.264 and HEVC/H.265 movie versions failing to group together.
- Fixed newly imported movie summaries skipping detail loading.
+- Fixed Xtream series losing some or all of their episodes after another series was opened (#166). Episode ids are now unique per series instead of per provider, and series cached before the fix are re-fetched the next time they are opened.
+- Fixed M3U channels sharing a `tvg-id` but using different stream URLs or Acestream hashes from being incorrectly treated as the same channel (#231).
- Fixed background movie refresh crashes when saved provider credentials cannot be decrypted.
- Fixed cropped video during adaptive resolution changes on affected Android TV emulators.
diff --git a/docs/DATABASE_MIGRATION_INVARIANTS.md b/docs/DATABASE_MIGRATION_INVARIANTS.md
index f3ecd004..bf8535e4 100644
--- a/docs/DATABASE_MIGRATION_INVARIANTS.md
+++ b/docs/DATABASE_MIGRATION_INVARIANTS.md
@@ -17,4 +17,11 @@ Every schema change must satisfy this checklist before the database version is a
- Current schema: v81.
- Exported historical origins: v1 and v3-v80; v2 has no committed Room schema export.
- Required migration coverage: `StreamVaultDatabaseMigrationTest` must validate exported origins through v81 plus populated direct/multi-hop preservation fixtures.
-- Migration 79 → 80 idempotently applies both local schema additions; migration 80 → 81 repairs the episode index for v80 databases created before this fix.
+- Migration 78 → 79 scopes episode uniqueness to the owning series and expires hydrated series detail timestamps.
+- Migration 79 → 80 adds the four Xtream live receipt columns; migration 80 → 81 creates the durable Stalker live-category retry table and its provider index.
+- Versions 79 and 80 were reordered during branch integration. The discarded branch schemas have no upgrade users and are not supported migration origins; their episode-index repair is intentionally omitted.
+
+## Validation (2026-10-10)
+
+- All 45 `StreamVaultDatabaseMigrationTest` tests passed on `Television_4K_2(AVD) - 16` using `:data:connectedDebugAndroidTest -Pandroid.testInstrumentationRunnerArguments.class=com.streamvault.data.local.StreamVaultDatabaseMigrationTest`.
+- Coverage includes every committed historical schema to v81, populated v78 → v80 → v81 receipt preservation, and direct v80 → v81 Stalker retry creation with episode/timestamp preservation and provider-delete cascade checks.