I like this project. Was looking for exactly a construct like this.
BUT this is mentally wrong thought.
A newly installed app or an all very close to the current development state does not need as much migrations as a very old version of the app.
I am trying my best to explain it with this example:
The far left evolutionary state needs the most migrations.
Walk on two legs.
Loose hair.
Use tools.
Use advanced tools.
Put on some clothes. :-)
The tool using evolutionary state just needs two more migrations.
Use advanced tools.
Put on some clothes. :-)
But a child of the modern human (newly installed app in this case) does not need a single migration. All newly features and data states are already built in. It can every introduce problems.
I came up with a solution where I leverage the BuildConfig.VERSION_CODE.
public Migrator createMigration() {
for (int i = PrefManager.with(mContext).getInt(CURRENT_VERSIONCODE, 0); i <= BuildConfig.VERSION_CODE; i++) {
switch (i) {
case 14:
return new Migrator(mContext, new V1Migration(mContext));
break;
case 34:
return new Migrator(mContext, new V2Migration(mContext), new V3Migration(mContext));
case 77:
return new Migrator(mContext, new V4Migration(mContext));
break;
}
}
//throw new... ?!
return null;
}
A for loop will iterate from 0 to currentVersionCode.
In very iteration a switch will look for an intoduced SharedPreference value of VERSION_CODE.
The whole process will only be started if currentVersioncode < latestSavedVersioncode:
But in the current migrator version an error is thrown, when I am on - let's say - versioncode 20. Then the first case I will jump in is the case34 with V2Migration and V3Migration. But the Migrator complains that V1Migration hasn't run. But V1Migration is not needed in a version higher 14, it is built in already.
I like this project. Was looking for exactly a construct like this. BUT this is mentally wrong thought. A newly installed app or an all very close to the current development state does not need as much migrations as a very old version of the app. I am trying my best to explain it with this example:
The far left evolutionary state needs the most migrations.
The tool using evolutionary state just needs two more migrations.
But a child of the modern human (newly installed app in this case) does not need a single migration. All newly features and data states are already built in. It can every introduce problems.
I came up with a solution where I leverage the BuildConfig.VERSION_CODE.
Hope this helps.