-
Notifications
You must be signed in to change notification settings - Fork 86
WIP: Introduce gormsupport.Versioning to auto increment a model's Version on update and set to 0 on create #2263
base: master
Are you sure you want to change the base?
Conversation
Looks good to me. Are you working on the item mentioned in the description? Also how about changing other places where version is used? |
Codecov Report
@@ Coverage Diff @@
## master #2263 +/- ##
==========================================
- Coverage 69.52% 69.41% -0.11%
==========================================
Files 176 176
Lines 16670 16397 -273
==========================================
- Hits 11589 11382 -207
+ Misses 3957 3922 -35
+ Partials 1124 1093 -31
Continue to review full report at Codecov.
|
@baijum I have worked on the items mentioned in the description and need to finish test fixups. Not doing that today but on Friday maybe. |
…SOURCE_DATABASE=1 F8_RESOURCE_UNIT_TEST=1 go test -v ./controller -run TestSpaceController
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
What is the story/task reference for this PR? |
There is none. This is cleanup work and stabilization work. Do we have an issue for this already? I don't want to open an issue for all the cleanups I'm doing. |
TL;DR
This fictional code:
can be simplified to just:
This is
About
The change is best explained with a comment from the code.
At first sight it doesn't look like this PR is helping much but we can easily forget to increment a
Version
field onUPDATE
or to set it to 0 onINSERT
. If you embedgormsupport.Versioning
in your struct this cannot happen because Gorm will call theBeforeUpdate
/BeforeCreate
function of any model object if it exists.We make sure that upon creation the version will be
0
, no matter what the user specified. This is done with theBeforeCreate
callback.What models already embed the
Versioning
struct?gormsupport.Versioning
here because we update the spacetemplates quite often during tests and currently this does not respect any versioning whatsoever. Will have to look into this in another PR.This adds the
gormsupport.Versioning
struct as discussed in https://chat.openshift.io/developers/pl/js3udrouwidfjqwjx7zr7n6aga