Archived
Added support for teacher column
This commit is contained in:
@@ -4,10 +4,12 @@ import android.content.Context
|
||||
import androidx.room.Database
|
||||
import androidx.room.Room
|
||||
import androidx.room.RoomDatabase
|
||||
import androidx.room.migration.Migration
|
||||
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
import com.denizd.substitutionplan.models.Food
|
||||
import com.denizd.substitutionplan.models.Subst
|
||||
|
||||
@Database(entities = [Subst::class, Food::class], version = 5, exportSchema = false)
|
||||
@Database(entities = [Subst::class, Food::class], version = 6, exportSchema = false)
|
||||
internal abstract class SubstDatabase : RoomDatabase() {
|
||||
|
||||
abstract fun substDao(): SubstDao
|
||||
@@ -15,6 +17,12 @@ internal abstract class SubstDatabase : RoomDatabase() {
|
||||
companion object {
|
||||
|
||||
private var instance: SubstDatabase? = null
|
||||
private val addTeacherColumn = object : Migration(5, 6) {
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL(
|
||||
"ALTER TABLE subst_table ADD COLUMN teacher TEXT NOT NULL DEFAULT ''")
|
||||
}
|
||||
}
|
||||
|
||||
fun getInstance(context: Context): SubstDatabase? {
|
||||
if (instance == null) {
|
||||
@@ -22,7 +30,7 @@ internal abstract class SubstDatabase : RoomDatabase() {
|
||||
instance = Room.databaseBuilder(context.applicationContext,
|
||||
SubstDatabase::class.java,
|
||||
"subst_database")
|
||||
.fallbackToDestructiveMigration()
|
||||
.addMigrations(addTeacherColumn)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user