{"action":"created","issue":{"url":"https://api.github.com/repos/keystonejs/keystone/issues/990","labels_url":"https://api.github.com/repos/keystonejs/keystone/issues/990/labels{/name}","comments_url":"https://api.github.com/repos/keystonejs/keystone/issues/990/comments","events_url":"https://api.github.com/repos/keystonejs/keystone/issues/990/events","html_url":"https://github.com/keystonejs/keystone/issues/990","id":56521037,"number":990,"title":"Updates / createItems Improvements","user":{"login":"webteckie","id":5872515,"avatar_url":"https://avatars.githubusercontent.com/u/5872515?v=3","gravatar_id":"","url":"https://api.github.com/users/webteckie","html_url":"https://github.com/webteckie","followers_url":"https://api.github.com/users/webteckie/followers","following_url":"https://api.github.com/users/webteckie/following{/other_user}","gists_url":"https://api.github.com/users/webteckie/gists{/gist_id}","starred_url":"https://api.github.com/users/webteckie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/webteckie/subscriptions","organizations_url":"https://api.github.com/users/webteckie/orgs","repos_url":"https://api.github.com/users/webteckie/repos","events_url":"https://api.github.com/users/webteckie/events{/privacy}","received_events_url":"https://api.github.com/users/webteckie/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/keystonejs/keystone/labels/suggestion","name":"suggestion","color":"4a558a"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":15,"created_at":"2015-02-04T12:34:08Z","updated_at":"2015-12-14T22:58:53Z","closed_at":null,"body":"I'm going to open this issue to jot down all requirements with the hope of implementing an updates / createItems flow that meets various use cases in a way that maintains data consistency and integrity.  Feel free to add on if you have other updates/createItems requirements.\r\n\r\n**Updates/createItems should resolve relationship dependencies across updates files**\r\n```\r\nupdates-1.js:\r\nThing-1: [\r\n    {item-1: name: \"cheese pizza\", __ref: item_cheese_pizza}\r\n]\r\n\r\nupdates-2.js:\r\nThing-2: [\r\n    {item-1_ref: \"item_cheese_pizza\"\r\n]\r\n```\r\nNOTE:  one possible approach is to pass in the refs lookup into createItems so as to let the updates module itself keep track of the refs lookup array across updates.\r\n\r\n**Updates/createItems should resolve relationship dependencies from DB**\r\n```\r\nupdates-1.js:\r\nThing-1: [\r\n    {item-1: name: \"cheese pizza\"}\r\n]\r\n\r\nupdates-2.js:\r\nThing-2: [\r\n    {item-1_ref: \"cheese-pizza\"}\r\n]\r\n```\r\nNOTE:  here a DEV would need to ensure that Thing-1 uses slugs as well as that Thing-1::item-1 will, indeed, resolve to a slug value of \"cheese-pizza\".\r\n\r\n**Updates/createItems should validate / detect errors/integrity issues before committing any items to the DB.**\r\n\r\nNOTE:  one possible approach is to do a first pass over createItems with a \"save = false\" argument that prevents items from getting saved.  To address requirement 2 above a slugs lookup array should also be kept across updates(?).\r\n\r\n**Updates/createItems should do one atomic save per item.  Currently, because it does 2 passes over the items, it does one save and then when it resolves relationships it does another save of the same document.  However, there isn't any guarantees that the first save did not mutate the document using a pre/post save hook.  If that happens when the 2nd save may run into issues since pre/post save hooks may assume one atomic save operation when going about their logic.**\r\n\r\nNOTE:  I have issues with this!\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/keystonejs/keystone/issues/comments/164587232","html_url":"https://github.com/keystonejs/keystone/issues/990#issuecomment-164587232","issue_url":"https://api.github.com/repos/keystonejs/keystone/issues/990","id":164587232,"user":{"login":"creynders","id":436347,"avatar_url":"https://avatars.githubusercontent.com/u/436347?v=3","gravatar_id":"","url":"https://api.github.com/users/creynders","html_url":"https://github.com/creynders","followers_url":"https://api.github.com/users/creynders/followers","following_url":"https://api.github.com/users/creynders/following{/other_user}","gists_url":"https://api.github.com/users/creynders/gists{/gist_id}","starred_url":"https://api.github.com/users/creynders/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/creynders/subscriptions","organizations_url":"https://api.github.com/users/creynders/orgs","repos_url":"https://api.github.com/users/creynders/repos","events_url":"https://api.github.com/users/creynders/events{/privacy}","received_events_url":"https://api.github.com/users/creynders/received_events","type":"User","site_admin":false},"created_at":"2015-12-14T22:58:53Z","updated_at":"2015-12-14T22:58:53Z","body":"Here for instance:https://github.com/d-pac/d-pac.cms/blob/db39bbecd71a2c8b7ceb8836320d16a7c28f3c78/batch/copyAssessment.js#L28\r\nI create an Assessment, but need its `id` to create other stuff too that have a relationship to it. Everything gets pushed into a save queue and saved one-by-one."}}