From 8a37a8a732a7792154db5f3ec025aaaec00c514c Mon Sep 17 00:00:00 2001 From: ashiagr Date: Mon, 6 Feb 2023 17:04:41 +0530 Subject: [PATCH] Add migration --- .../pocketcasts/models/db/AppDatabaseTest.kt | 3 +- .../pocketcasts/models/db/AppDatabase.kt | 30 ++++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/app/src/androidTest/java/au/com/shiftyjelly/pocketcasts/models/db/AppDatabaseTest.kt b/app/src/androidTest/java/au/com/shiftyjelly/pocketcasts/models/db/AppDatabaseTest.kt index 42f1ec30752..73278924ee6 100644 --- a/app/src/androidTest/java/au/com/shiftyjelly/pocketcasts/models/db/AppDatabaseTest.kt +++ b/app/src/androidTest/java/au/com/shiftyjelly/pocketcasts/models/db/AppDatabaseTest.kt @@ -137,7 +137,8 @@ class AppDatabaseTest { AppDatabase.MIGRATION_69_70, AppDatabase.MIGRATION_70_71, AppDatabase.MIGRATION_71_72, - AppDatabase.MIGRATION_72_73 + AppDatabase.MIGRATION_72_73, + AppDatabase.MIGRATION_73_74 ) .build() // close the database and release any stream resources when the test finishes diff --git a/modules/services/model/src/main/java/au/com/shiftyjelly/pocketcasts/models/db/AppDatabase.kt b/modules/services/model/src/main/java/au/com/shiftyjelly/pocketcasts/models/db/AppDatabase.kt index 4930d52a994..821d9024d37 100644 --- a/modules/services/model/src/main/java/au/com/shiftyjelly/pocketcasts/models/db/AppDatabase.kt +++ b/modules/services/model/src/main/java/au/com/shiftyjelly/pocketcasts/models/db/AppDatabase.kt @@ -378,6 +378,33 @@ abstract class AppDatabase : RoomDatabase() { ) } + val MIGRATION_73_74 = addMigration(73, 74) { database -> + database.execSQL( + """ + CREATE TABLE IF NOT EXISTS search_history ( + _id INTEGER PRIMARY KEY AUTOINCREMENT, + modified INTEGER NOT NULL, + term TEXT, + podcast_uuid TEXT, + podcast_title TEXT, + podcast_author TEXT, + folder_uuid TEXT, + folder_title TEXT, + folder_color INTEGER, + folder_podcastIds TEXT, + episode_uuid TEXT, + episode_title TEXT, + episode_publishedDate INTEGER, + episode_duration REAL + ); + """.trimIndent() + ) + database.execSQL("CREATE UNIQUE INDEX IF NOT EXISTS `index_search_history_term` ON search_history (`term`)") + database.execSQL("CREATE UNIQUE INDEX IF NOT EXISTS `index_search_history_podcast_uuid` ON search_history (`podcast_uuid`);") + database.execSQL("CREATE UNIQUE INDEX IF NOT EXISTS `index_search_history_folder_uuid` ON search_history (`folder_uuid`)") + database.execSQL("CREATE UNIQUE INDEX IF NOT EXISTS `index_search_history_episode_uuid` ON search_history (`episode_uuid`)") + } + fun addMigrations(databaseBuilder: Builder, context: Context) { databaseBuilder.addMigrations( addMigration(1, 2) { }, @@ -740,7 +767,8 @@ abstract class AppDatabase : RoomDatabase() { MIGRATION_69_70, MIGRATION_70_71, MIGRATION_71_72, - MIGRATION_72_73 + MIGRATION_72_73, + MIGRATION_73_74 ) }