I have a database that lives in the assets folder. It contains pre-populated tables, as well as tables which store user entered data. Now, we have finished up another part of the app and are planning to unlock this section. The issue is that the database now contains new tables with pre-populated values. How do I migrate the existing database with the new database, making sure to maintain the user entered data and the new pre-populated table values. I have the following code, which correctly adds the new table to the existing database, but it does not retain the pre-populated data. I know I could use insert statements to add the pre-populated data, but that would be require hundreds of statements.
val migration1to2 = object: Migration(1, 2) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL("CREATE TABLE IF NOT EXISTS 'users' ('id' INTEGER NOT NULL UNIQUE, 'name' TEXT NOT NULL, 'specid' TEXT NOT NULL, PRIMARY KEY('id' AUTOINCREMENT))")
}
}
Room.databaseBuilder(context, InspectionDatabase::class.java, "inspection_db.db")
.createFromAsset("inspection.db")
.setJournalMode(JournalMode.TRUNCATE)
.allowMainThreadQueries()
.addMigrations(InspectionDatabase.migration1to2)
.build()