Skip to content
This repository has been archived by the owner on Aug 7, 2024. It is now read-only.

Commit

Permalink
fix: invalid database migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
SuhasDissa committed Oct 25, 2023
1 parent 712df34 commit 7ef9143
Showing 1 changed file with 1 addition and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import androidx.room.migration.Migration
import app.suhasdissa.vibeyou.backend.database.dao.RawDao
import app.suhasdissa.vibeyou.backend.database.dao.SearchDao
import app.suhasdissa.vibeyou.backend.database.dao.SongsDao
Expand All @@ -16,7 +15,7 @@ import app.suhasdissa.vibeyou.backend.database.entities.SongEntity
SongEntity::class,
SearchQuery::class
],
version = 2,
version = 1,
exportSchema = false
)
abstract class SongDatabase : RoomDatabase() {
Expand All @@ -29,19 +28,13 @@ abstract class SongDatabase : RoomDatabase() {
@Volatile
private var INSTANCE: SongDatabase? = null

private val MIGRATION_1_2 = Migration(1, 2) { database ->
database.execSQL("ALTER TABLE song ADD COLUMN creationDate INTEGER")
database.execSQL("ALTER TABLE song ADD COLUMN dateAdded INTEGER")
}

fun getDatabase(context: Context): SongDatabase {
return INSTANCE ?: synchronized(this) {
val instance = Room.databaseBuilder(
context.applicationContext,
SongDatabase::class.java,
"song_database"
)
.addMigrations(MIGRATION_1_2)
.fallbackToDestructiveMigration()
.allowMainThreadQueries().build()
INSTANCE = instance
Expand Down

0 comments on commit 7ef9143

Please sign in to comment.