Skip to content

Instantly share code, notes, and snippets.

@0phelia
Created December 4, 2019 15:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0phelia/1fe6e794017bd90fdd84ad90060cca68 to your computer and use it in GitHub Desktop.
Save 0phelia/1fe6e794017bd90fdd84ad90060cca68 to your computer and use it in GitHub Desktop.
// add to app build file
kapt {
arguments {
arg("room.schemaLocation", "$projectDir/schemas".toString())
}
}
// set expostSchema to true#
...exportSchema = true
// copypaste new scheme and add to migration variable
val MIGRATION_1_2: Migration = object : Migration(1, 2) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL("CREATE TABLE IF NOT EXIS..........")
}
}
// provide migatin variable to DB
fun getInstance(context: Context): AppDb? {
if (sInstance == null) {
synchronized(LOCK) {
sInstance = Room.databaseBuilder(
context.applicationContext,
AppDb::class.java, DbConfig.DB_NAME
)
.addMigrations(MIGRATION_1_2)
.build()
}
}
return sInstance
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment