RushOrm
RushOrm copied to clipboard
issues after new dbVersion (every time)
Hi, every time I need change my model structure (example add new class), I increment by one dbVersion (no debug mode), compile and install app, when code run .save() of object app gets stuck until I manually kill it. If I increment dbVersion by two (so from 10 to 12) for example, db is cleared and I lost all data on saved db. But then app start run correctly, and I can run .save() without problems.
Classes are very simple like:
@RushTableAnnotation public class StepsData extends RushObject {
private long timestamp;
private long date;
private int time;
private int steps;
/* Classes must include an empty constructor */
public StepsData() {
}
public StepsData(long timestamp, int steps) {
this.timestamp = timestamp;
this.steps=steps;
}
public long getTimestamp() {
return timestamp;
}
public void setTimestamp(long timestamp) {
this.timestamp = timestamp;
}
public int getSteps() {
return steps;
}
public void setSteps(int steps) {
this.steps = steps;
}
public long getDate() {
return date;
}
public void setDate(long date) {
this.date = date;
}
public int getTime() {
return time;
}
public void setTime(int time) {
this.time = time;
}
}
and this is my rush init config
AndroidInitializeConfig config = new AndroidInitializeConfig(context); RushConfig con = new RushConfig() { @Override public String dbName() { return "settings.ba"; }
@Override
public int dbVersion() {
return 14;
}
@Override
public boolean inDebug() {
return false;
}
@Override
public boolean log() {
return false;
}
@Override
public boolean requireTableAnnotation() {
return true;
}
@Override
public boolean usingMySql() {
return false;
}
@Override
public boolean userBulkInsert() {
return false;
}
@Override
public boolean orderColumnsAlphabetically() {
return true;
}
};
List<Class<? extends Rush>> classes = new ArrayList<>();
classes.add(Statistics.class);
classes.add(AppStatistics.class);
classes.add(StatLogs.class);
classes.add(ActivityData.class);
classes.add(HeartMonitorData.class);
classes.add(StepsData.class);
config.setClasses(classes);
config.setRushConfig(con);
config.setInitializeListener(new InitializeListener() {
@Override
public void initialized(boolean b) {
if(b)
{
initDB();
}
}
});
RushCore.initialize(config);
I am running into what sounds like the same issue. I added a boolean field to a table and incremented the db version. When launched the migration looked to run but then when my code touched the table I got a crash telling me to increment the db version.
I have not been successful with the migrations with Rush yet. Even with simple things like above. I will have to do migrations in my next production build so will have to figure out a way to fix it.
I'm glad to not be the only one having this issue! but none wants reply...
Most embarrassing issue come with final users...can't find a solution to prevent data loss. Each time I need an upgrade (new changes) I'm scared publish app, because more than one user will run into this issue
I have tried overriding the upgrade manager and wiping the tables that need to be upgraded and pull the latest data but that did not work. It's not a massive deal for me to resync my database so I'm thinking I'll have to drop the database completely before initializing rush. Then just allow it to start up as if a new database. Sucks though
This will eventually be a deal breaker issue for us when our app is much bigger.
I have tried in failure to get the app to stop crashing on migration. Even though the migration runs because I implemented the upgrade manager
public class DatabaseUpgradeManager extends ReflectionUpgradeManager {
public DatabaseUpgradeManager(Logger logger, RushConfig rushConfig) {
super(logger, rushConfig);
}
@Override
public void upgrade(List<Class<? extends Rush>> classList, UpgradeCallback callback, Map<Class<? extends Rush>, AnnotationCache> annotationCache) {
// Anything we want to do before the upgrade do it here...
// wipe the database on upgrade and force a reload. Log it...
ApplicationContext.ApiLogger.logString("**** Doing Database Migration ***");
// this does nothing and actually causes more problems. Drop database before init of RUSH
//RushCore.getInstance().clearDatabase();
super.upgrade(classList, callback, annotationCache);
ApplicationContext.ApiLogger.logString("**** Database Migration Complete ***");
// Anything to cleanup after upgrade do it here...
}
}
I see in my log that the upgrade runs and finishes and then when I access the table that is changed I get the crash telling me to change the db version number. If I increment it 1 more again and then re-run the app it usually succeeds . So when I do my next app upgrade I'm running this code before I initialize RUSH in my application class
private void checkDatabaseForUpgrade(SharedPreferences settings){
String settingsDbVersion = settings.getString("DBVersion", "");
if( !settingsDbVersion .equalsIgnoreCase(BuildConfig.VERSION_NAME) ){
ApiLogger.logString("Deleting Database For Upgrade...");
this.deleteDatabase("mydb.db");
// save the version out so we don't wipe it again
ApiLogger.logString("Setting [" + BuildConfig.VERSION_NAME + "] as active database...");
SharedPreferences.Editor editor = settings.edit();
editor.putString("DBVersion", BuildConfig.VERSION_NAME);
editor.commit();
}
}
Down side is I have to re-sync my database from the server but at least the app is no longer crashing.