[6.7.2]数据库升级
This commit is contained in:
@@ -4,11 +4,13 @@ import android.content.Context
|
|||||||
import androidx.room.Database
|
import androidx.room.Database
|
||||||
import androidx.room.Room
|
import androidx.room.Room
|
||||||
import androidx.room.RoomDatabase
|
import androidx.room.RoomDatabase
|
||||||
|
import androidx.room.migration.Migration
|
||||||
|
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 接管记录数据库
|
* 接管记录数据库
|
||||||
*/
|
*/
|
||||||
@Database(entities = [RecordInfo::class], version = 1, exportSchema = false)
|
@Database(entities = [RecordInfo::class], version = 2, exportSchema = false)
|
||||||
abstract class RecordDb: RoomDatabase() {
|
abstract class RecordDb: RoomDatabase() {
|
||||||
|
|
||||||
abstract fun recordDao(): RecordDao
|
abstract fun recordDao(): RecordDao
|
||||||
@@ -18,10 +20,17 @@ abstract class RecordDb: RoomDatabase() {
|
|||||||
|
|
||||||
private var db: RecordDb? = null
|
private var db: RecordDb? = null
|
||||||
|
|
||||||
|
private val Migration_One_Two = object : Migration(1, 2) {
|
||||||
|
override fun migrate(database: SupportSQLiteDatabase) {
|
||||||
|
database.execSQL("ALTER TABLE take_over_record ADD COLUMN bagId INTEGER")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun getDb(context: Context): RecordDb {
|
fun getDb(context: Context): RecordDb {
|
||||||
if (db == null) {
|
if (db == null) {
|
||||||
db = Room.databaseBuilder(context.applicationContext, RecordDb::class.java, RECORD_DB_NAME)
|
db = Room.databaseBuilder(context.applicationContext, RecordDb::class.java, RECORD_DB_NAME)
|
||||||
|
.addMigrations(Migration_One_Two)
|
||||||
.fallbackToDestructiveMigration()
|
.fallbackToDestructiveMigration()
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user