Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion app/src/main/kotlin/com/metrolist/music/db/MusicDatabase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ import java.util.Date
import java.util.Locale

class MusicDatabase(
private val delegate: InternalDatabase,
val delegate: InternalDatabase,
) : DatabaseDao by delegate.dao {
val speedDialDao: SpeedDialDao
get() = delegate.speedDialDao
Expand Down Expand Up @@ -177,6 +177,7 @@ abstract class InternalDatabase : RoomDatabase() {
MIGRATION_21_24,
MIGRATION_22_24,
MIGRATION_24_25,
MIGRATION_38_37,
).fallbackToDestructiveMigration(dropAllTables = true)
.setJournalMode(RoomDatabase.JournalMode.WRITE_AHEAD_LOGGING)
.setTransactionExecutor(
Expand Down Expand Up @@ -813,6 +814,21 @@ val MIGRATION_24_25 =
}
}

val MIGRATION_38_37 =
object : Migration(38, 37) {
override fun migrate(db: SupportSQLiteDatabase) {
db.execSQL("DROP TABLE IF EXISTS `ArtistPageCache`")
db.execSQL(
"CREATE TABLE IF NOT EXISTS `artist_new` (`id` TEXT NOT NULL, `name` TEXT NOT NULL, `thumbnailUrl` TEXT, `channelId` TEXT, `lastUpdateTime` INTEGER NOT NULL, `bookmarkedAt` INTEGER, `isLocal` INTEGER NOT NULL DEFAULT 0, `isPodcastChannel` INTEGER NOT NULL DEFAULT 0, PRIMARY KEY(`id`))"
)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
db.execSQL(
"INSERT INTO `artist_new` (`id`, `name`, `thumbnailUrl`, `channelId`, `lastUpdateTime`, `bookmarkedAt`, `isLocal`, `isPodcastChannel`) SELECT `id`, `name`, `thumbnailUrl`, `channelId`, `lastUpdateTime`, `bookmarkedAt`, `isLocal`, `isPodcastChannel` FROM `artist`"
)
db.execSQL("DROP TABLE `artist`")
db.execSQL("ALTER TABLE `artist_new` RENAME TO `artist`")
}
}

class Migration29To30 : AutoMigrationSpec {
override fun onPostMigrate(db: SupportSQLiteDatabase) {
// Ensure isVideo column exists (safeguard)
Expand Down
12 changes: 5 additions & 7 deletions app/src/main/kotlin/com/metrolist/music/di/AppModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,15 @@ object AppModule {

@Singleton
@Provides
fun provideInternalDatabase(
fun provideDatabase(
@ApplicationContext context: Context,
): InternalDatabase = Room
.databaseBuilder(context, InternalDatabase::class.java, InternalDatabase.DB_NAME)
.build()
): MusicDatabase = InternalDatabase.newInstance(context)

@Singleton
@Provides
fun provideDatabase(
internalDatabase: InternalDatabase,
): MusicDatabase = MusicDatabase(internalDatabase)
fun provideInternalDatabase(
database: MusicDatabase,
): InternalDatabase = database.delegate

@Singleton
@Provides
Expand Down
Loading