Skip to content

Commit 92e9c3e

Browse files
committed
Fix DatabaseMigrationTest
Complete removal of unneeded index, and remove default value for `remote_playlists.display_index`.
1 parent 4591c09 commit 92e9c3e

5 files changed

Lines changed: 37 additions & 48 deletions

File tree

app/schemas/org.schabi.newpipe.database.AppDatabase/9.json

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"formatVersion": 1,
33
"database": {
44
"version": 9,
5-
"identityHash": "94596ea2227c63dd78b472ea4a83f1c4",
5+
"identityHash": "7591e8039faa74d8c0517dc867af9d3e",
66
"entities": [
77
{
88
"tableName": "subscriptions",
@@ -362,17 +362,7 @@
362362
"uid"
363363
]
364364
},
365-
"indices": [
366-
{
367-
"name": "index_playlists_name",
368-
"unique": false,
369-
"columnNames": [
370-
"name"
371-
],
372-
"orders": [],
373-
"createSql": "CREATE INDEX IF NOT EXISTS `index_playlists_name` ON `${TABLE_NAME}` (`name`)"
374-
}
375-
],
365+
"indices": [],
376366
"foreignKeys": []
377367
},
378368
{
@@ -511,15 +501,6 @@
511501
]
512502
},
513503
"indices": [
514-
{
515-
"name": "index_remote_playlists_name",
516-
"unique": false,
517-
"columnNames": [
518-
"name"
519-
],
520-
"orders": [],
521-
"createSql": "CREATE INDEX IF NOT EXISTS `index_remote_playlists_name` ON `${TABLE_NAME}` (`name`)"
522-
},
523504
{
524505
"name": "index_remote_playlists_service_id_url",
525506
"unique": true,
@@ -743,7 +724,7 @@
743724
"views": [],
744725
"setupQueries": [
745726
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
746-
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '94596ea2227c63dd78b472ea4a83f1c4')"
727+
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '7591e8039faa74d8c0517dc867af9d3e')"
747728
]
748729
}
749730
}

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

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,10 @@ class DatabaseMigrationTest {
122122
)
123123

124124
testHelper.runMigrationsAndValidate(
125-
AppDatabase.DATABASE_NAME, Migrations.DB_VER_6,
126-
true, Migrations.MIGRATION_5_6
125+
AppDatabase.DATABASE_NAME,
126+
Migrations.DB_VER_9,
127+
true,
128+
Migrations.MIGRATION_8_9
127129
)
128130

129131
val migratedDatabaseV3 = getMigratedDatabase()
@@ -209,6 +211,11 @@ class DatabaseMigrationTest {
209211
true, Migrations.MIGRATION_7_8
210212
)
211213

214+
testHelper.runMigrationsAndValidate(
215+
AppDatabase.DATABASE_NAME, Migrations.DB_VER_9,
216+
true, Migrations.MIGRATION_8_9
217+
)
218+
212219
val migratedDatabaseV8 = getMigratedDatabase()
213220
val listFromDB = migratedDatabaseV8.searchHistoryDAO().all.blockingFirst()
214221

@@ -220,25 +227,27 @@ class DatabaseMigrationTest {
220227

221228
@Test
222229
fun migrateDatabaseFrom8to9() {
223-
val databaseInV5 = testHelper.createDatabase(AppDatabase.DATABASE_NAME, Migrations.DB_VER_5)
230+
val databaseInV8 = testHelper.createDatabase(AppDatabase.DATABASE_NAME, Migrations.DB_VER_8)
224231

225232
val localUid1: Long
226233
val localUid2: Long
227234
val remoteUid1: Long
228235
val remoteUid2: Long
229-
databaseInV5.run {
236+
databaseInV8.run {
230237
localUid1 = insert(
231238
"playlists", SQLiteDatabase.CONFLICT_FAIL,
232239
ContentValues().apply {
233240
put("name", DEFAULT_NAME + "1")
234-
put("thumbnail_url", DEFAULT_THUMBNAIL)
241+
put("is_thumbnail_permanent", false)
242+
put("thumbnail_stream_id", -1)
235243
}
236244
)
237245
localUid2 = insert(
238246
"playlists", SQLiteDatabase.CONFLICT_FAIL,
239247
ContentValues().apply {
240248
put("name", DEFAULT_NAME + "2")
241-
put("thumbnail_url", DEFAULT_THUMBNAIL)
249+
put("is_thumbnail_permanent", false)
250+
put("thumbnail_stream_id", -1)
242251
}
243252
)
244253
delete(
@@ -267,33 +276,35 @@ class DatabaseMigrationTest {
267276
}
268277

269278
testHelper.runMigrationsAndValidate(
270-
AppDatabase.DATABASE_NAME, Migrations.DB_VER_6,
271-
true, Migrations.MIGRATION_5_6
279+
AppDatabase.DATABASE_NAME,
280+
Migrations.DB_VER_9,
281+
true,
282+
Migrations.MIGRATION_8_9
272283
)
273284

274-
val migratedDatabaseV6 = getMigratedDatabase()
275-
var localListFromDB = migratedDatabaseV6.playlistDAO().all.blockingFirst()
276-
var remoteListFromDB = migratedDatabaseV6.playlistRemoteDAO().all.blockingFirst()
285+
val migratedDatabaseV9 = getMigratedDatabase()
286+
var localListFromDB = migratedDatabaseV9.playlistDAO().all.blockingFirst()
287+
var remoteListFromDB = migratedDatabaseV9.playlistRemoteDAO().all.blockingFirst()
277288

278289
assertEquals(1, localListFromDB.size)
279290
assertEquals(localUid2, localListFromDB[0].uid)
280-
assertEquals(0, localListFromDB[0].displayIndex)
291+
assertEquals(-1, localListFromDB[0].displayIndex)
281292
assertEquals(1, remoteListFromDB.size)
282293
assertEquals(remoteUid1, remoteListFromDB[0].uid)
283-
assertEquals(0, remoteListFromDB[0].displayIndex)
294+
assertEquals(-1, remoteListFromDB[0].displayIndex)
284295

285-
val localUid3 = migratedDatabaseV6.playlistDAO().insert(
286-
PlaylistEntity(DEFAULT_NAME + "3", DEFAULT_THUMBNAIL, -1)
296+
val localUid3 = migratedDatabaseV9.playlistDAO().insert(
297+
PlaylistEntity(DEFAULT_NAME + "3", false, -1, -1)
287298
)
288-
val remoteUid3 = migratedDatabaseV6.playlistRemoteDAO().insert(
299+
val remoteUid3 = migratedDatabaseV9.playlistRemoteDAO().insert(
289300
PlaylistRemoteEntity(
290301
DEFAULT_THIRD_SERVICE_ID, DEFAULT_NAME, DEFAULT_THIRD_URL,
291302
DEFAULT_THUMBNAIL, DEFAULT_UPLOADER_NAME, -1, 10
292303
)
293304
)
294305

295-
localListFromDB = migratedDatabaseV6.playlistDAO().all.blockingFirst()
296-
remoteListFromDB = migratedDatabaseV6.playlistRemoteDAO().all.blockingFirst()
306+
localListFromDB = migratedDatabaseV9.playlistDAO().all.blockingFirst()
307+
remoteListFromDB = migratedDatabaseV9.playlistRemoteDAO().all.blockingFirst()
297308
assertEquals(2, localListFromDB.size)
298309
assertEquals(localUid3, localListFromDB[1].uid)
299310
assertEquals(-1, localListFromDB[1].displayIndex)

app/src/main/java/org/schabi/newpipe/database/Migrations.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,12 +278,13 @@ public void migrate(@NonNull final SupportSQLiteDatabase database) {
278278
+ "(`uid` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "
279279
+ "`service_id` INTEGER NOT NULL, `name` TEXT, `url` TEXT, "
280280
+ "`thumbnail_url` TEXT, `uploader` TEXT, "
281-
+ "`display_index` INTEGER NOT NULL DEFAULT 0,"
281+
+ "`display_index` INTEGER NOT NULL,"
282282
+ "`stream_count` INTEGER)");
283283
database.execSQL("INSERT INTO `remote_playlists_tmp` (`uid`, `service_id`, "
284-
+ "`name`, `url`, `thumbnail_url`, `uploader`, `stream_count`)"
284+
+ "`name`, `url`, `thumbnail_url`, `uploader`, `display_index`, "
285+
+ "`stream_count`)"
285286
+ "SELECT `uid`, `service_id`, `name`, `url`, `thumbnail_url`, `uploader`, "
286-
+ "`stream_count` FROM `remote_playlists`");
287+
+ "-1, `stream_count` FROM `remote_playlists`");
287288

288289
// Replace the old table, note that this also removes the index on the name which
289290
// we don't need anymore.

app/src/main/java/org/schabi/newpipe/database/playlist/model/PlaylistEntity.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,14 @@
33
import androidx.room.ColumnInfo;
44
import androidx.room.Entity;
55
import androidx.room.Ignore;
6-
import androidx.room.Index;
76
import androidx.room.PrimaryKey;
87

9-
import static org.schabi.newpipe.database.playlist.model.PlaylistEntity.PLAYLIST_NAME;
108
import static org.schabi.newpipe.database.playlist.model.PlaylistEntity.PLAYLIST_TABLE;
119

1210
import org.schabi.newpipe.R;
1311
import org.schabi.newpipe.database.playlist.PlaylistMetadataEntry;
1412

15-
@Entity(tableName = PLAYLIST_TABLE,
16-
indices = {@Index(value = {PLAYLIST_NAME})})
13+
@Entity(tableName = PLAYLIST_TABLE)
1714
public class PlaylistEntity {
1815

1916
public static final String DEFAULT_THUMBNAIL = "drawable://"

app/src/main/java/org/schabi/newpipe/database/playlist/model/PlaylistRemoteEntity.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
@Entity(tableName = REMOTE_PLAYLIST_TABLE,
2323
indices = {
24-
@Index(value = {REMOTE_PLAYLIST_NAME}),
2524
@Index(value = {REMOTE_PLAYLIST_SERVICE_ID, REMOTE_PLAYLIST_URL}, unique = true)
2625
})
2726
public class PlaylistRemoteEntity implements PlaylistLocalItem {

0 commit comments

Comments
 (0)