{"action":"created","issue":{"url":"https://api.github.com/repos/fabric8-services/fabric8-wit/issues/2263","repository_url":"https://api.github.com/repos/fabric8-services/fabric8-wit","labels_url":"https://api.github.com/repos/fabric8-services/fabric8-wit/issues/2263/labels{/name}","comments_url":"https://api.github.com/repos/fabric8-services/fabric8-wit/issues/2263/comments","events_url":"https://api.github.com/repos/fabric8-services/fabric8-wit/issues/2263/events","html_url":"https://github.com/fabric8-services/fabric8-wit/pull/2263","id":355076097,"node_id":"MDExOlB1bGxSZXF1ZXN0MjExNjg3ODQw","number":2263,"title":"Introduce gormsupport.Versioning to auto increment a model's Version on update and set to 0 on create","user":{"login":"kwk","id":193408,"node_id":"MDQ6VXNlcjE5MzQwOA==","avatar_url":"https://avatars3.githubusercontent.com/u/193408?v=4","gravatar_id":"","url":"https://api.github.com/users/kwk","html_url":"https://github.com/kwk","followers_url":"https://api.github.com/users/kwk/followers","following_url":"https://api.github.com/users/kwk/following{/other_user}","gists_url":"https://api.github.com/users/kwk/gists{/gist_id}","starred_url":"https://api.github.com/users/kwk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kwk/subscriptions","organizations_url":"https://api.github.com/users/kwk/orgs","repos_url":"https://api.github.com/users/kwk/repos","events_url":"https://api.github.com/users/kwk/events{/privacy}","received_events_url":"https://api.github.com/users/kwk/received_events","type":"User","site_admin":false},"labels":[{"id":554289356,"node_id":"MDU6TGFiZWw1NTQyODkzNTY=","url":"https://api.github.com/repos/fabric8-services/fabric8-wit/labels/:bath:%20cleanup","name":":bath: cleanup","color":"fef2c0","default":false},{"id":475336085,"node_id":"MDU6TGFiZWw0NzUzMzYwODU=","url":"https://api.github.com/repos/fabric8-services/fabric8-wit/labels/:no_entry_sign:%20hold","name":":no_entry_sign: hold","color":"fbca04","default":false},{"id":554289152,"node_id":"MDU6TGFiZWw1NTQyODkxNTI=","url":"https://api.github.com/repos/fabric8-services/fabric8-wit/labels/:recycle:%20refactoring","name":":recycle: refactoring","color":"c2e0c6","default":false},{"id":436888669,"node_id":"MDU6TGFiZWw0MzY4ODg2Njk=","url":"https://api.github.com/repos/fabric8-services/fabric8-wit/labels/database","name":"database","color":"f9d0c4","default":false}],"state":"open","locked":false,"assignee":{"login":"kwk","id":193408,"node_id":"MDQ6VXNlcjE5MzQwOA==","avatar_url":"https://avatars3.githubusercontent.com/u/193408?v=4","gravatar_id":"","url":"https://api.github.com/users/kwk","html_url":"https://github.com/kwk","followers_url":"https://api.github.com/users/kwk/followers","following_url":"https://api.github.com/users/kwk/following{/other_user}","gists_url":"https://api.github.com/users/kwk/gists{/gist_id}","starred_url":"https://api.github.com/users/kwk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kwk/subscriptions","organizations_url":"https://api.github.com/users/kwk/orgs","repos_url":"https://api.github.com/users/kwk/repos","events_url":"https://api.github.com/users/kwk/events{/privacy}","received_events_url":"https://api.github.com/users/kwk/received_events","type":"User","site_admin":false},"assignees":[{"login":"kwk","id":193408,"node_id":"MDQ6VXNlcjE5MzQwOA==","avatar_url":"https://avatars3.githubusercontent.com/u/193408?v=4","gravatar_id":"","url":"https://api.github.com/users/kwk","html_url":"https://github.com/kwk","followers_url":"https://api.github.com/users/kwk/followers","following_url":"https://api.github.com/users/kwk/following{/other_user}","gists_url":"https://api.github.com/users/kwk/gists{/gist_id}","starred_url":"https://api.github.com/users/kwk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kwk/subscriptions","organizations_url":"https://api.github.com/users/kwk/orgs","repos_url":"https://api.github.com/users/kwk/repos","events_url":"https://api.github.com/users/kwk/events{/privacy}","received_events_url":"https://api.github.com/users/kwk/received_events","type":"User","site_admin":false}],"milestone":null,"comments":0,"created_at":"2018-08-29T09:33:12Z","updated_at":"2018-08-29T14:55:58Z","closed_at":null,"author_association":"COLLABORATOR","pull_request":{"url":"https://api.github.com/repos/fabric8-services/fabric8-wit/pulls/2263","html_url":"https://github.com/fabric8-services/fabric8-wit/pull/2263","diff_url":"https://github.com/fabric8-services/fabric8-wit/pull/2263.diff","patch_url":"https://github.com/fabric8-services/fabric8-wit/pull/2263.patch"},"body":"The change is best explained with a comment from the code.\r\n\r\n```go\r\n// Versioning can be embedded into model structs that want to have a Version\r\n// column which will automatically be incremented before each update. For the\r\n// first creation of a model the initial version will always be overwritten with\r\n// 0 nomatter what the user specified in the model itself. The model itself is\r\n// not changed in any cases, just the DB query for INSERT and UPDATE is touched.\r\ntype Versioning struct {\r\n\tVersion int `json:\"version\"`\r\n}\r\n```\r\n\r\nAt first sight it doesn't look like this PR is helping much but we can easily forget to increment a `Version` field on `UPDATE` or to set it to 0 on `INSERT`. If you embed `gormsupport.Versioning` in your struct this cannot happen because Gorm will call the `BeforeUpdate`/`BeforeCreate` function of any model object if it exists.\r\n\r\nWe make sure that upon creation the version will be `0`, no matter what the user specified. This is done with the `BeforeCreate` callback.\r\n\r\n## What models already embed the `Versioning` struct?\r\n\r\n- [x] workitem.WorkItemStorage\r\n- [x] link.WorkItemLinkCategory\r\n\r\nThis adds the `gormsupport.Versioning` struct as discussed in https://chat.openshift.io/developers/pl/js3udrouwidfjqwjx7zr7n6aga\r\n\r\n## TODO\r\n\r\n- [ ] Automatically add to `WHERE` clause using `scope.Search.Where(\"version=?\", v.Version)` in `BeforeUpdate` (Test is needed and documentation needs to be updated. The rest is already there.)"},"comment":{"url":"https://api.github.com/repos/fabric8-services/fabric8-wit/issues/comments/416984312","html_url":"https://github.com/fabric8-services/fabric8-wit/pull/2263#issuecomment-416984312","issue_url":"https://api.github.com/repos/fabric8-services/fabric8-wit/issues/2263","id":416984312,"node_id":"MDEyOklzc3VlQ29tbWVudDQxNjk4NDMxMg==","user":{"login":"baijum","id":121129,"node_id":"MDQ6VXNlcjEyMTEyOQ==","avatar_url":"https://avatars3.githubusercontent.com/u/121129?v=4","gravatar_id":"","url":"https://api.github.com/users/baijum","html_url":"https://github.com/baijum","followers_url":"https://api.github.com/users/baijum/followers","following_url":"https://api.github.com/users/baijum/following{/other_user}","gists_url":"https://api.github.com/users/baijum/gists{/gist_id}","starred_url":"https://api.github.com/users/baijum/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/baijum/subscriptions","organizations_url":"https://api.github.com/users/baijum/orgs","repos_url":"https://api.github.com/users/baijum/repos","events_url":"https://api.github.com/users/baijum/events{/privacy}","received_events_url":"https://api.github.com/users/baijum/received_events","type":"User","site_admin":false},"created_at":"2018-08-29T14:55:58Z","updated_at":"2018-08-29T14:55:58Z","author_association":"MEMBER","body":"Looks good to me. Are you working on the item mentioned in the description? Also how about changing other places where version is used?"}}
{"actor":{"display_login":"baijum"}}