use of com.health.openscale.core.database.ScaleUserDatabase in project openScale by oliexdev.
the class OpenScale method migrateSQLtoRoom.
private void migrateSQLtoRoom() {
if (!context.getDatabasePath(ScaleUserDatabase.DATABASE_NAME).exists() || !context.getDatabasePath(ScaleDatabase.DATABASE_NAME).exists()) {
return;
}
ScaleDatabase scaleDB = new ScaleDatabase(context);
ScaleUserDatabase scaleUserDB = new ScaleUserDatabase(context);
List<ScaleUser> oldScaleUserList = scaleUserDB.getScaleUserList();
if (scaleDB.getReadableDatabase().getVersion() == 6 && userDAO.getAll().isEmpty() && !oldScaleUserList.isEmpty()) {
Toast.makeText(context, "Migrating old SQL database to new database format...", Toast.LENGTH_LONG).show();
userDAO.insertAll(oldScaleUserList);
for (ScaleUser user : oldScaleUserList) {
List<ScaleMeasurement> oldScaleMeasurementList = scaleDB.getScaleDataList(user.getId());
measurementDAO.insertAll(oldScaleMeasurementList);
}
Toast.makeText(context, "Finished migrating old SQL database to new database format", Toast.LENGTH_LONG).show();
}
scaleUserDB.close();
scaleDB.close();
}
Aggregations