Using Android API 32 and Room 2.4.2
Room database is created like this
companion object {
@Volatile
private var INSTANCE: AppDatabase? = null
fun getDatabase(context: Context): AppDatabase {
val tempInstance = INSTANCE
if (tempInstance != null)
return tempInstance
synchronized(this) {
val name = "mydb.db"
val instance = Room.databaseBuilder(
context.applicationContext,
AppDatabase::class.java,
name
).apply {
fallbackToDestructiveMigration()
createFromAsset(name)
}.build()
INSTANCE = instance
return instance
}
}
}
The schema is version 1
and prepopulated db asset is version 0
. When the app is started for the frist time the room db is created and
populated with the asset data correctly. But whenever the app is restarted the room db is created and populated anew.
If I change the prepopulated version to 1
then the recreation does not happen.
Why does it fallback to distructive and copy data when prepopulated version is less
than the target one?