DDB Enhanced: Allow custom versioning
Motivation and Context
This PR builds on the work started in issue #3894 where the VersionedRecordExtension didn't support starting version numbers at 0, requiring clients to use Integer objects (with null initial values) rather than long primitives. As mentioned by @akiesler in the original issue, developers might expect versions to start at 0 and increment from there, rather than having a special case where the value must be initialized to null.
This implementation allows the extension to be more flexible by allowing:
- Starting versions at 0 (or any non-negative long)
- Configuring custom increment values (only positive numbers)
- Supporting these configs both at the extension level and via annotations
Modifications
- Refactored the
VersionedRecordExtensionto support explicitstartAtandincrementByvalues via builder methods (making it opt-in). - Expanded the
DynamoDbVersionAttributeannotation to supportstartAtandincrementByparameters - Added validation to prevent negative startAt values and non-positive incrementBy values
Testing
- Custom
startAtandincrementByvalues through both builder and annotations - Validation of illegal values (negative
startAt, zero/negativeincrementBy) - Precedence rules between annotation and builder configurations
- Version incrementation for both initial and existing records
- Edge cases with different configuration combinations
Thank you for picking up this change! It will greatly simplify our version handling. Please let me know if I can do anything to help.
Quality Gate passed
Issues
25 New issues
0 Accepted issues
Measures
0 Security Hotspots
93.6% Coverage on New Code
0.0% Duplication on New Code
Fixed edge case in the isInitialVersion function. Previously it was not evaluating the precedence that annotation values should take over builder values.
This caused inconsistent behavior when both annotation and builder values were both provided with different values, potentially treating records as initial versions incorrectly when their version matched the builder's startAt value but not the annotation's value.
This is now fixed. Added a test case that combines input from both the builder and the annotation.
Quality Gate passed
Issues
11 New issues
0 Accepted issues
Measures
0 Security Hotspots
90.7% Coverage on New Code
0.0% Duplication on New Code
This pull request has been closed and the conversation has been locked. Comments on closed PRs are hard for our team to see. If you need more assistance, please open a new issue that references this one.