Closed gamerover98 closed 1 year ago
This is really nice and allows for migrations to be defined successively without having to "react" to whatever is in the config, as the current migration service forces one to do. Very neat! I will leave some comments a bit later but think this is a great enhancement—thank you!
Hi, I would like to ask you if you could make the changes to the test section that you requested me to modify in whichever way you think is best. It would be beneficial to include new test suites to cover more use cases, such as migration from various different versions. Currently, the only available test pertains to the migration from a single version, specifically from versions 1 to 2.
Thank you—I'm on it! I've also merged Migration
with VersionMigration
and re-added fromVersion()
. That way, VersionMigration
has the entire information about what it migrates, and the VersionMigrationService can create the map without the calling user having to do that.
You'll get to have your say once the changes are in of course. In particular, I think we'll need a last round to talk about what happens if the version is out of range. I pushed you to remove the exceptions, but interestingly, not having exceptions means if a wrong value is set as version, we can never really "get out of that". At least not if the version is too small. I'm currently writing tests and will make sure to have such scenarios as well, so once the tests are done we'll have more to refer to, and I hope I'll have more of a full picture :smile:
I'm still working on adding Javadoc on VersionMigrationService but wanted to push my other changes in case I was taking too long haha. This took a long time because it took me a while to form an opinion on what the migration service should do in various corner cases. Happy for your input on this, and everything else.
Basically I ended up setting the version to the current version no matter what. Because if the migration service triggers a reset, it means that any old values (properties that no longer exist in the SettingsHolder classes, or properties whose value has changed and is now deemed invalid) would anyway disappear. So I think it's dangerous to run migrations and maybe not end at the current version and to save that version instead of the current version.
What I'm saying is a situation like this:
Migrations:
1 to 2
2 to 3
4 to 5
Current version: 5
YAML file:
version: 1
The migration service will set that to 5 even though it only ran the migrations 1->2, 2->3. I'll try to reflect that in the Javadoc of the VersionMigrationService, which, as mentioned, I'm rewriting for the third time and trying to phrase sensibly :joy:
Edit: Since this might not fit everyone's needs, I tried to separate the logic into smaller portions that could be overridden. Hence the birth of runApplicableMigrations
, which could be called by someone that wants to override performMigrations
, OR the other way around: the former method could be overridden if a tweak is needed in how the migrations are picked up, without having to duplicate the rest. I think it worked out OK, but I'm sorry if you're a bit surprised that I turned everything upside down!
That's okay, this is your project, and my code was meant to serve as a reference for something else. I've always wanted to incorporate this feature into my projects.
I'm thankful for the opportunity to assist you, and I'll strive to provide similar help for other ideas as well. Have a nice day 😸
I very much appreciate your contributions—be it in form of code, comments or opinions. Happy for your thoughts on any issue as well as any review findings you have in any ConfigMe code. It helps make the right decisions for integrators of ConfigMe like you :smile: I mainly function issue-based, so even if it's not really a bug or feature, creating a GitHub issue is a great way to discuss a topic! Otherwise, my Discord username is cyrkel
.
I've pushed the documentation for the migration service. Please comment on anything you don't like in this PR. I will do the same later with a clearer head (might be tomorrow). So I think a merge is right on the horizon now :grin:
Thanks again for everything! Really appreciate your work on this project.
Hi, this pull request contains a new feature that supports configuration versioning. The complete description of this feature is fully described at Proposal for New Feature - Version Control Support.
Scenario
Let's imagine that we have an old config like the following:
Our software requires an update and we have a new configuration but we need to migrate from the old to the new one with a result like to following:
Obviously, the migration must keep the old property values.
Do the migration
First of all, this is the
SettingsHolder
of our updated software:Now we can register this
SettingsManager
:Edge cases
What happens if...
handleTooLowerVersion(int version)
method.handleTooHigherVersion(int version)
method.Other changes
The
PlainMigrationService.moveProperty(oldProperty, newProperty, reader, configurationData)
method has been moved to a new class calledMigrationUtils
.Looking forward to your feedback and collaboration on this enhancement. Thank you
Fix #344