@@ -11,6 +11,8 @@ import androidx.room.Query
1111import androidx.room.Room
1212import androidx.room.RoomDatabase
1313import androidx.room.Upsert
14+ import androidx.room.migration.Migration
15+ import androidx.sqlite.db.SupportSQLiteDatabase
1416
1517
1618@Dao
@@ -61,13 +63,25 @@ abstract class ServerDatabase : RoomDatabase() {
6163 @Volatile
6264 private var instance: ServerDatabase ? = null
6365
66+ private val MIGRATION_1_2 = object : Migration (1 , 2 ) {
67+ override fun migrate (database : SupportSQLiteDatabase ) {
68+ database.execSQL(" ALTER TABLE Server ADD COLUMN size INTEGER" )
69+ database.execSQL(" ALTER TABLE Server ADD COLUMN count INTEGER" )
70+ database.execSQL(" ALTER TABLE Server ADD COLUMN shorts INTEGER" )
71+ database.execSQL(" ALTER TABLE Server ADD COLUMN humanSize TEXT" )
72+ }
73+ }
74+
6475 fun getInstance (context : Context ): ServerDatabase =
6576 instance ? : synchronized(this ) {
6677 instance ? : Room .databaseBuilder(
6778 context.applicationContext,
6879 ServerDatabase ::class .java,
6980 " server-database"
70- ).build().also { instance = it }
81+ )
82+ // .fallbackToDestructiveMigration(true) // Destructive Operation
83+ .addMigrations(MIGRATION_1_2 )
84+ .build().also { instance = it }
7185 }
7286 }
7387}
0 commit comments