-
-
Save harryhan24/0ee1c60fcef57052869d562008cc0439 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private val callback = object : RoomDatabase.Callback() { | |
override fun onCreate(db: SupportSQLiteDatabase) { | |
try { | |
// First time to database was created, check if user upgraded from a previous | |
// version of the app that was using ORMLite and migrate data if needed. | |
val context = TradeMeApp.getContext() | |
val previousDB = context.applicationContext.getDatabasePath(PREVIOUS_DATABASE_FILE) | |
if (previousDB.exists()) { | |
MigrateToRoom(previousDB, context.component.database).execute() | |
} | |
} catch (exception: Exception) { /* log error */ } | |
} | |
} | |
@JvmStatic | |
fun getBuilder(context: Context): RoomDatabase.Builder<Database> { | |
return Room.databaseBuilder( | |
context, | |
Database::class.java, | |
DATABASE_FILE) | |
.addMigrations(*migrations) | |
.addCallback(callback) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment