RushOrm
RushOrm copied to clipboard
Modify data after database migration
I've been looking for a way to make data modifications before or after a migration is run and I'm not sure if there is a way to do it or not. It doesn't look like it. I have a fairly complex data structure and simple migrations have corrupted the data which is causing the app to crash sometimes. Luckily this has only happened in testing so far.
What I need is some way to know that a migration is about to occur so I can do some action on the data. Right now it might be as simple as clear all data from the database and let my app pull the data from the server again after the migration is complete.
Hi,
There is no inbuilt way to do pre and post migration actions, that said should be pretty simple to do.
(Not tested this but should work)
Create a class that extends the default RushUpgradeManager
class MyUpgradeManager extends ReflectionUpgradeManager {
public MyUpgradeManager(Logger logger, RushConfig rushConfig) {
super(logger, rushConfig);
}
@Override
public void upgrade(List<Class<? extends Rush>> classList, UpgradeCallback callback, Map<Class<? extends Rush>, AnnotationCache> annotationCache) {
// Pre upgrade actions
super.upgrade(classList, callback, annotationCache);
// Post upgrade actions
}
}
Then set it on the RushConfig
AndroidInitializeConfig config = new AndroidInitializeConfig(getApplicationContext());
config.setUpgradeManager(new MyUpgradeManager(config.getRushLogger(), config.getRushConfig()));
RushCore.initialize(config);
Let me know if you have any issues.
Thanks
Awesome, thank you. I'll check this out.