From 92e9c3e42eed0d8f5f29210e6527f8351edfc4da Mon Sep 17 00:00:00 2001 From: Stypox Date: Fri, 29 Mar 2024 20:43:55 +0100 Subject: [PATCH] Fix DatabaseMigrationTest Complete removal of unneeded index, and remove default value for `remote_playlists.display_index`. --- .../9.json | 25 ++-------- .../newpipe/database/DatabaseMigrationTest.kt | 47 ++++++++++++------- .../schabi/newpipe/database/Migrations.java | 7 +-- .../playlist/model/PlaylistEntity.java | 5 +- .../playlist/model/PlaylistRemoteEntity.java | 1 - 5 files changed, 37 insertions(+), 48 deletions(-) diff --git a/app/schemas/org.schabi.newpipe.database.AppDatabase/9.json b/app/schemas/org.schabi.newpipe.database.AppDatabase/9.json index 0fcd383af..aced06c0a 100644 --- a/app/schemas/org.schabi.newpipe.database.AppDatabase/9.json +++ b/app/schemas/org.schabi.newpipe.database.AppDatabase/9.json @@ -2,7 +2,7 @@ "formatVersion": 1, "database": { "version": 9, - "identityHash": "94596ea2227c63dd78b472ea4a83f1c4", + "identityHash": "7591e8039faa74d8c0517dc867af9d3e", "entities": [ { "tableName": "subscriptions", @@ -362,17 +362,7 @@ "uid" ] }, - "indices": [ - { - "name": "index_playlists_name", - "unique": false, - "columnNames": [ - "name" - ], - "orders": [], - "createSql": "CREATE INDEX IF NOT EXISTS `index_playlists_name` ON `${TABLE_NAME}` (`name`)" - } - ], + "indices": [], "foreignKeys": [] }, { @@ -511,15 +501,6 @@ ] }, "indices": [ - { - "name": "index_remote_playlists_name", - "unique": false, - "columnNames": [ - "name" - ], - "orders": [], - "createSql": "CREATE INDEX IF NOT EXISTS `index_remote_playlists_name` ON `${TABLE_NAME}` (`name`)" - }, { "name": "index_remote_playlists_service_id_url", "unique": true, @@ -743,7 +724,7 @@ "views": [], "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, '94596ea2227c63dd78b472ea4a83f1c4')" + "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '7591e8039faa74d8c0517dc867af9d3e')" ] } } \ No newline at end of file diff --git a/app/src/androidTest/java/org/schabi/newpipe/database/DatabaseMigrationTest.kt b/app/src/androidTest/java/org/schabi/newpipe/database/DatabaseMigrationTest.kt index f71880366..a34cfece6 100644 --- a/app/src/androidTest/java/org/schabi/newpipe/database/DatabaseMigrationTest.kt +++ b/app/src/androidTest/java/org/schabi/newpipe/database/DatabaseMigrationTest.kt @@ -122,8 +122,10 @@ class DatabaseMigrationTest { ) testHelper.runMigrationsAndValidate( - AppDatabase.DATABASE_NAME, Migrations.DB_VER_6, - true, Migrations.MIGRATION_5_6 + AppDatabase.DATABASE_NAME, + Migrations.DB_VER_9, + true, + Migrations.MIGRATION_8_9 ) val migratedDatabaseV3 = getMigratedDatabase() @@ -209,6 +211,11 @@ class DatabaseMigrationTest { true, Migrations.MIGRATION_7_8 ) + testHelper.runMigrationsAndValidate( + AppDatabase.DATABASE_NAME, Migrations.DB_VER_9, + true, Migrations.MIGRATION_8_9 + ) + val migratedDatabaseV8 = getMigratedDatabase() val listFromDB = migratedDatabaseV8.searchHistoryDAO().all.blockingFirst() @@ -220,25 +227,27 @@ class DatabaseMigrationTest { @Test fun migrateDatabaseFrom8to9() { - val databaseInV5 = testHelper.createDatabase(AppDatabase.DATABASE_NAME, Migrations.DB_VER_5) + val databaseInV8 = testHelper.createDatabase(AppDatabase.DATABASE_NAME, Migrations.DB_VER_8) val localUid1: Long val localUid2: Long val remoteUid1: Long val remoteUid2: Long - databaseInV5.run { + databaseInV8.run { localUid1 = insert( "playlists", SQLiteDatabase.CONFLICT_FAIL, ContentValues().apply { put("name", DEFAULT_NAME + "1") - put("thumbnail_url", DEFAULT_THUMBNAIL) + put("is_thumbnail_permanent", false) + put("thumbnail_stream_id", -1) } ) localUid2 = insert( "playlists", SQLiteDatabase.CONFLICT_FAIL, ContentValues().apply { put("name", DEFAULT_NAME + "2") - put("thumbnail_url", DEFAULT_THUMBNAIL) + put("is_thumbnail_permanent", false) + put("thumbnail_stream_id", -1) } ) delete( @@ -267,33 +276,35 @@ class DatabaseMigrationTest { } testHelper.runMigrationsAndValidate( - AppDatabase.DATABASE_NAME, Migrations.DB_VER_6, - true, Migrations.MIGRATION_5_6 + AppDatabase.DATABASE_NAME, + Migrations.DB_VER_9, + true, + Migrations.MIGRATION_8_9 ) - val migratedDatabaseV6 = getMigratedDatabase() - var localListFromDB = migratedDatabaseV6.playlistDAO().all.blockingFirst() - var remoteListFromDB = migratedDatabaseV6.playlistRemoteDAO().all.blockingFirst() + val migratedDatabaseV9 = getMigratedDatabase() + var localListFromDB = migratedDatabaseV9.playlistDAO().all.blockingFirst() + var remoteListFromDB = migratedDatabaseV9.playlistRemoteDAO().all.blockingFirst() assertEquals(1, localListFromDB.size) assertEquals(localUid2, localListFromDB[0].uid) - assertEquals(0, localListFromDB[0].displayIndex) + assertEquals(-1, localListFromDB[0].displayIndex) assertEquals(1, remoteListFromDB.size) assertEquals(remoteUid1, remoteListFromDB[0].uid) - assertEquals(0, remoteListFromDB[0].displayIndex) + assertEquals(-1, remoteListFromDB[0].displayIndex) - val localUid3 = migratedDatabaseV6.playlistDAO().insert( - PlaylistEntity(DEFAULT_NAME + "3", DEFAULT_THUMBNAIL, -1) + val localUid3 = migratedDatabaseV9.playlistDAO().insert( + PlaylistEntity(DEFAULT_NAME + "3", false, -1, -1) ) - val remoteUid3 = migratedDatabaseV6.playlistRemoteDAO().insert( + val remoteUid3 = migratedDatabaseV9.playlistRemoteDAO().insert( PlaylistRemoteEntity( DEFAULT_THIRD_SERVICE_ID, DEFAULT_NAME, DEFAULT_THIRD_URL, DEFAULT_THUMBNAIL, DEFAULT_UPLOADER_NAME, -1, 10 ) ) - localListFromDB = migratedDatabaseV6.playlistDAO().all.blockingFirst() - remoteListFromDB = migratedDatabaseV6.playlistRemoteDAO().all.blockingFirst() + localListFromDB = migratedDatabaseV9.playlistDAO().all.blockingFirst() + remoteListFromDB = migratedDatabaseV9.playlistRemoteDAO().all.blockingFirst() assertEquals(2, localListFromDB.size) assertEquals(localUid3, localListFromDB[1].uid) assertEquals(-1, localListFromDB[1].displayIndex) diff --git a/app/src/main/java/org/schabi/newpipe/database/Migrations.java b/app/src/main/java/org/schabi/newpipe/database/Migrations.java index 9d641965d..c9f630869 100644 --- a/app/src/main/java/org/schabi/newpipe/database/Migrations.java +++ b/app/src/main/java/org/schabi/newpipe/database/Migrations.java @@ -278,12 +278,13 @@ public final class Migrations { + "(`uid` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, " + "`service_id` INTEGER NOT NULL, `name` TEXT, `url` TEXT, " + "`thumbnail_url` TEXT, `uploader` TEXT, " - + "`display_index` INTEGER NOT NULL DEFAULT 0," + + "`display_index` INTEGER NOT NULL," + "`stream_count` INTEGER)"); database.execSQL("INSERT INTO `remote_playlists_tmp` (`uid`, `service_id`, " - + "`name`, `url`, `thumbnail_url`, `uploader`, `stream_count`)" + + "`name`, `url`, `thumbnail_url`, `uploader`, `display_index`, " + + "`stream_count`)" + "SELECT `uid`, `service_id`, `name`, `url`, `thumbnail_url`, `uploader`, " - + "`stream_count` FROM `remote_playlists`"); + + "-1, `stream_count` FROM `remote_playlists`"); // Replace the old table, note that this also removes the index on the name which // we don't need anymore. diff --git a/app/src/main/java/org/schabi/newpipe/database/playlist/model/PlaylistEntity.java b/app/src/main/java/org/schabi/newpipe/database/playlist/model/PlaylistEntity.java index cb18027d0..e0c1a06b7 100644 --- a/app/src/main/java/org/schabi/newpipe/database/playlist/model/PlaylistEntity.java +++ b/app/src/main/java/org/schabi/newpipe/database/playlist/model/PlaylistEntity.java @@ -3,17 +3,14 @@ package org.schabi.newpipe.database.playlist.model; import androidx.room.ColumnInfo; import androidx.room.Entity; import androidx.room.Ignore; -import androidx.room.Index; import androidx.room.PrimaryKey; -import static org.schabi.newpipe.database.playlist.model.PlaylistEntity.PLAYLIST_NAME; import static org.schabi.newpipe.database.playlist.model.PlaylistEntity.PLAYLIST_TABLE; import org.schabi.newpipe.R; import org.schabi.newpipe.database.playlist.PlaylistMetadataEntry; -@Entity(tableName = PLAYLIST_TABLE, - indices = {@Index(value = {PLAYLIST_NAME})}) +@Entity(tableName = PLAYLIST_TABLE) public class PlaylistEntity { public static final String DEFAULT_THUMBNAIL = "drawable://" diff --git a/app/src/main/java/org/schabi/newpipe/database/playlist/model/PlaylistRemoteEntity.java b/app/src/main/java/org/schabi/newpipe/database/playlist/model/PlaylistRemoteEntity.java index 50c3899f1..60027a057 100644 --- a/app/src/main/java/org/schabi/newpipe/database/playlist/model/PlaylistRemoteEntity.java +++ b/app/src/main/java/org/schabi/newpipe/database/playlist/model/PlaylistRemoteEntity.java @@ -21,7 +21,6 @@ import static org.schabi.newpipe.database.playlist.model.PlaylistRemoteEntity.RE @Entity(tableName = REMOTE_PLAYLIST_TABLE, indices = { - @Index(value = {REMOTE_PLAYLIST_NAME}), @Index(value = {REMOTE_PLAYLIST_SERVICE_ID, REMOTE_PLAYLIST_URL}, unique = true) }) public class PlaylistRemoteEntity implements PlaylistLocalItem {