Skip to content

Commit efb136e

Browse files
test ran
1 parent 5dd8e6e commit efb136e

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

app/src/androidTest/java/org/schabi/newpipe/database/DatabaseMigrationTest.kt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,42 @@ class DatabaseMigrationTest {
323323
assertEquals(-1, remoteListFromDB[1].displayIndex)
324324
}
325325

326+
@Test
327+
fun migrateDatabaseFrom9to10() {
328+
val databaseInV9 = testHelper.createDatabase(AppDatabase.DATABASE_NAME, Migrations.DB_VER_9)
329+
330+
val localUid1: Long
331+
databaseInV9.run {
332+
localUid1 = insert(
333+
"playlists", SQLiteDatabase.CONFLICT_FAIL,
334+
ContentValues().apply {
335+
put("name", DEFAULT_NAME + "1")
336+
put("is_thumbnail_permanent", false)
337+
put("thumbnail_stream_id", -1)
338+
put("display_index", -1)
339+
}
340+
)
341+
close()
342+
}
343+
344+
testHelper.runMigrationsAndValidate(
345+
AppDatabase.DATABASE_NAME,
346+
Migrations.DB_VER_10,
347+
true,
348+
Migrations.MIGRATION_9_10
349+
)
350+
351+
val migratedDatabaseV10 = getMigratedDatabase()
352+
val localListFromDB = migratedDatabaseV10.playlistDAO().getAll().blockingFirst()
353+
354+
assertEquals(1, localListFromDB.size)
355+
// folderId should exist and be null for existing playlists
356+
assertNull(localListFromDB[0].folderId)
357+
358+
val foldersFromDB = migratedDatabaseV10.playlistFolderDAO().getAll().blockingFirst()
359+
assertEquals(0, foldersFromDB.size)
360+
}
361+
326362
private fun getMigratedDatabase(): AppDatabase {
327363
val database: AppDatabase = Room.databaseBuilder(
328364
ApplicationProvider.getApplicationContext(),

0 commit comments

Comments
 (0)