{"action":"created","comment":{"url":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/comments/59746907","id":59746907,"diff_hunk":"@@ -1,36 +1,75 @@\n+\"\"\"\n+This migration will change params['node'] to be the node (if it isn't node already), and will set\n+params['registration'] equal to the associated registration.\n+\"\"\"\n+\n import logging\n \n from modularodm import Q\n \n-from website.models import NodeLog\n+from website.models import NodeLog, Node, RegistrationApproval\n from website.app import init_app\n \n from scripts import utils as script_utils\n+from framework.mongo import database as db\n from framework.transactions.context import TokuTransaction\n \n logger = logging.getLogger(__name__)\n logging.basicConfig(level=logging.INFO)\n \n \n def get_targets():\n+    \"\"\"\n+    Fetches all registration-related logs except for project_registered.\n+\n+    project_registered log is not included because params already correct.\n+    \"\"\"\n     logs = NodeLog.find(\n-            Q('action', 'eq', 'embargo_approved') |\n-            Q('action', 'eq', 'embargo_initiated') |\n-            Q('action', 'eq', 'retraction_approved') |\n-            Q('action', 'eq', 'retraction_initiated') |\n-            Q('action', 'eq', 'registration_initiated')\n+        Q('action', 'eq', 'registration_initiated') |\n+        Q('action', 'eq', 'registration_approved') |\n+        Q('action', 'eq', 'registration_cancelled') |  # On staging, there are a few inconsistencies with these.  Majority of params['node'] are registrations, but a handful are nodes.\n+        Q('action', 'eq', 'retraction_initiated') |\n+        Q('action', 'eq', 'retraction_approved') |  # params['node'] is already equal to node.  Adds registration_field below.  Will be slow.\n+        Q('action', 'eq', 'retraction_cancelled') |\n+        Q('action', 'eq', 'embargo_initiated') |\n+        Q('action', 'eq', 'embargo_approved') |\n+        Q('action', 'eq', 'embargo_completed') |\n+        Q('action', 'eq', 'embargo_cancelled')\n     )\n     return logs\n \n \n+def get_registered_from(registration):\n+    \"\"\"\n+    Gets node registration was registered from.  Handles deleted registrations where registered_from is null.\n+\n+    \"\"\"\n+    if registration.registered_from:\n+        return registration.registered_from_id\n+    else:\n+        first_log = db['node'].find_one({'_id': registration._id})['logs'][0]\n+        return NodeLog.load(first_log).params['node']","path":"scripts/migrate_registration_logs.py","position":57,"original_position":57,"commit_id":"9ec5afd2dde7ab78aafe546c68b13966b43c928f","original_commit_id":"34c9154ff780ab2693e4badb9368eb47b23c65aa","user":{"login":"sloria","id":2379650,"avatar_url":"https://avatars.githubusercontent.com/u/2379650?v=3","gravatar_id":"","url":"https://api.github.com/users/sloria","html_url":"https://github.com/sloria","followers_url":"https://api.github.com/users/sloria/followers","following_url":"https://api.github.com/users/sloria/following{/other_user}","gists_url":"https://api.github.com/users/sloria/gists{/gist_id}","starred_url":"https://api.github.com/users/sloria/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sloria/subscriptions","organizations_url":"https://api.github.com/users/sloria/orgs","repos_url":"https://api.github.com/users/sloria/repos","events_url":"https://api.github.com/users/sloria/events{/privacy}","received_events_url":"https://api.github.com/users/sloria/received_events","type":"User","site_admin":false},"body":"Based on 638f73167fb, there was a time when we didn't add the `node` param for top-level projects. So you can use `params['project']` in those cases.","created_at":"2016-04-14T16:21:01Z","updated_at":"2016-04-14T16:21:01Z","html_url":"https://github.com/CenterForOpenScience/osf.io/pull/5462#discussion_r59746907","pull_request_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/5462","_links":{"self":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/comments/59746907"},"html":{"href":"https://github.com/CenterForOpenScience/osf.io/pull/5462#discussion_r59746907"},"pull_request":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/5462"}}},"pull_request":{"url":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/5462","id":66244197,"html_url":"https://github.com/CenterForOpenScience/osf.io/pull/5462","diff_url":"https://github.com/CenterForOpenScience/osf.io/pull/5462.diff","patch_url":"https://github.com/CenterForOpenScience/osf.io/pull/5462.patch","issue_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/issues/5462","number":5462,"state":"open","locked":false,"title":"[Ready to Review] Add registration info to params","user":{"login":"pattisdr","id":9755598,"avatar_url":"https://avatars.githubusercontent.com/u/9755598?v=3","gravatar_id":"","url":"https://api.github.com/users/pattisdr","html_url":"https://github.com/pattisdr","followers_url":"https://api.github.com/users/pattisdr/followers","following_url":"https://api.github.com/users/pattisdr/following{/other_user}","gists_url":"https://api.github.com/users/pattisdr/gists{/gist_id}","starred_url":"https://api.github.com/users/pattisdr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pattisdr/subscriptions","organizations_url":"https://api.github.com/users/pattisdr/orgs","repos_url":"https://api.github.com/users/pattisdr/repos","events_url":"https://api.github.com/users/pattisdr/events{/privacy}","received_events_url":"https://api.github.com/users/pattisdr/received_events","type":"User","site_admin":false},"body":"# Purpose\r\n\r\nThe migration in https://github.com/CenterForOpenScience/osf.io/pull/5335 drops references to registrations in registration logs.  Also, params['node'] points to the registration in some logs, and the node in others.\r\n\r\nThe overall goal is consistency among registration-related logs.  params['node'] will be set to `registered_from`.  params['registration'] will be the registration.  The later migration in https://github.com/CenterForOpenScience/osf.io/pull/4950 will add `original_node` fields (set equal to params['node']) and `node` fields, initially set equal to the nodes on the logs' backrefs, and afterwards, pertaining to the node the log resides on. \r\n\r\n# Changes\r\n- Adds params['registration'] for all registration-related logs.\r\n- Changes params['node'] to point to registered_from instead of registration.\r\n- Updates script migrate_registration_logs.py to migrate past logs.\r\n\r\n**Example**\r\nNode is ABC\r\nRegistration is DEF\r\noriginal_node and node fields are added in https://github.com/CenterForOpenScience/osf.io/pull/4950.  `original_node` is the node the log originally belonged to and `node` is where the log currently belongs. On a project, its original_node and node_fields will be the same.  But if I register that project, `original_node` will point to the project, and `node` will be the registration.\r\n\r\n```\r\nLog 123 on Node ABC\r\n\r\naction = registration_initiated\r\noriginal_node = ABC \r\nnode = ABC \r\nparams = {\r\n   \"node\": \"ABC\",\r\n   \"registration\": \"DEF\",\r\n   \"registration_approval\": \"sdfjkasf...\"\r\n}\r\n```\r\n\r\n\r\n\r\nWorking off of staging DB before https://github.com/CenterForOpenScience/osf.io/pull/5335 and https://github.com/CenterForOpenScience/osf.io/pull/4950 migrations\r\n### Before running updated scripts.migrate_registration_logs\r\n![screen shot 2016-04-13 at 2 26 05 pm](https://cloud.githubusercontent.com/assets/9755598/14512359/68f73f3e-01ac-11e6-9996-98d8fdd87fe2.png)\r\n### After: \r\n![screen shot 2016-04-13 at 7 15 11 pm](https://cloud.githubusercontent.com/assets/9755598/14512360/6c6e7f6a-01ac-11e6-9cb2-7c2f9d4c78b3.png)\r\n\r\n\r\n\r\n\r\n\r\n","created_at":"2016-04-12T23:22:49Z","updated_at":"2016-04-14T16:21:01Z","closed_at":null,"merged_at":null,"merge_commit_sha":"efbbc9e8708de26edb01a223e5e91ed3c09637c8","assignee":null,"milestone":{"url":"https://api.github.com/repos/CenterForOpenScience/osf.io/milestones/66","html_url":"https://github.com/CenterForOpenScience/osf.io/milestones/0.67.0","labels_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/milestones/66/labels","id":1627250,"number":66,"title":"0.67.0","description":"","creator":{"login":"sloria","id":2379650,"avatar_url":"https://avatars.githubusercontent.com/u/2379650?v=3","gravatar_id":"","url":"https://api.github.com/users/sloria","html_url":"https://github.com/sloria","followers_url":"https://api.github.com/users/sloria/followers","following_url":"https://api.github.com/users/sloria/following{/other_user}","gists_url":"https://api.github.com/users/sloria/gists{/gist_id}","starred_url":"https://api.github.com/users/sloria/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sloria/subscriptions","organizations_url":"https://api.github.com/users/sloria/orgs","repos_url":"https://api.github.com/users/sloria/repos","events_url":"https://api.github.com/users/sloria/events{/privacy}","received_events_url":"https://api.github.com/users/sloria/received_events","type":"User","site_admin":false},"open_issues":2,"closed_issues":69,"state":"open","created_at":"2016-03-07T21:04:43Z","updated_at":"2016-04-14T13:18:26Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/5462/commits","review_comments_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/5462/comments","review_comment_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/comments{/number}","comments_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/issues/5462/comments","statuses_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/statuses/9ec5afd2dde7ab78aafe546c68b13966b43c928f","head":{"label":"pattisdr:fix/add_registration_info_to_params","ref":"fix/add_registration_info_to_params","sha":"9ec5afd2dde7ab78aafe546c68b13966b43c928f","user":{"login":"pattisdr","id":9755598,"avatar_url":"https://avatars.githubusercontent.com/u/9755598?v=3","gravatar_id":"","url":"https://api.github.com/users/pattisdr","html_url":"https://github.com/pattisdr","followers_url":"https://api.github.com/users/pattisdr/followers","following_url":"https://api.github.com/users/pattisdr/following{/other_user}","gists_url":"https://api.github.com/users/pattisdr/gists{/gist_id}","starred_url":"https://api.github.com/users/pattisdr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pattisdr/subscriptions","organizations_url":"https://api.github.com/users/pattisdr/orgs","repos_url":"https://api.github.com/users/pattisdr/repos","events_url":"https://api.github.com/users/pattisdr/events{/privacy}","received_events_url":"https://api.github.com/users/pattisdr/received_events","type":"User","site_admin":false},"repo":{"id":35900874,"name":"osf.io","full_name":"pattisdr/osf.io","owner":{"login":"pattisdr","id":9755598,"avatar_url":"https://avatars.githubusercontent.com/u/9755598?v=3","gravatar_id":"","url":"https://api.github.com/users/pattisdr","html_url":"https://github.com/pattisdr","followers_url":"https://api.github.com/users/pattisdr/followers","following_url":"https://api.github.com/users/pattisdr/following{/other_user}","gists_url":"https://api.github.com/users/pattisdr/gists{/gist_id}","starred_url":"https://api.github.com/users/pattisdr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pattisdr/subscriptions","organizations_url":"https://api.github.com/users/pattisdr/orgs","repos_url":"https://api.github.com/users/pattisdr/repos","events_url":"https://api.github.com/users/pattisdr/events{/privacy}","received_events_url":"https://api.github.com/users/pattisdr/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/pattisdr/osf.io","description":"Facilitating Open Science","fork":true,"url":"https://api.github.com/repos/pattisdr/osf.io","forks_url":"https://api.github.com/repos/pattisdr/osf.io/forks","keys_url":"https://api.github.com/repos/pattisdr/osf.io/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pattisdr/osf.io/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pattisdr/osf.io/teams","hooks_url":"https://api.github.com/repos/pattisdr/osf.io/hooks","issue_events_url":"https://api.github.com/repos/pattisdr/osf.io/issues/events{/number}","events_url":"https://api.github.com/repos/pattisdr/osf.io/events","assignees_url":"https://api.github.com/repos/pattisdr/osf.io/assignees{/user}","branches_url":"https://api.github.com/repos/pattisdr/osf.io/branches{/branch}","tags_url":"https://api.github.com/repos/pattisdr/osf.io/tags","blobs_url":"https://api.github.com/repos/pattisdr/osf.io/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pattisdr/osf.io/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pattisdr/osf.io/git/refs{/sha}","trees_url":"https://api.github.com/repos/pattisdr/osf.io/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pattisdr/osf.io/statuses/{sha}","languages_url":"https://api.github.com/repos/pattisdr/osf.io/languages","stargazers_url":"https://api.github.com/repos/pattisdr/osf.io/stargazers","contributors_url":"https://api.github.com/repos/pattisdr/osf.io/contributors","subscribers_url":"https://api.github.com/repos/pattisdr/osf.io/subscribers","subscription_url":"https://api.github.com/repos/pattisdr/osf.io/subscription","commits_url":"https://api.github.com/repos/pattisdr/osf.io/commits{/sha}","git_commits_url":"https://api.github.com/repos/pattisdr/osf.io/git/commits{/sha}","comments_url":"https://api.github.com/repos/pattisdr/osf.io/comments{/number}","issue_comment_url":"https://api.github.com/repos/pattisdr/osf.io/issues/comments{/number}","contents_url":"https://api.github.com/repos/pattisdr/osf.io/contents/{+path}","compare_url":"https://api.github.com/repos/pattisdr/osf.io/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pattisdr/osf.io/merges","archive_url":"https://api.github.com/repos/pattisdr/osf.io/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pattisdr/osf.io/downloads","issues_url":"https://api.github.com/repos/pattisdr/osf.io/issues{/number}","pulls_url":"https://api.github.com/repos/pattisdr/osf.io/pulls{/number}","milestones_url":"https://api.github.com/repos/pattisdr/osf.io/milestones{/number}","notifications_url":"https://api.github.com/repos/pattisdr/osf.io/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pattisdr/osf.io/labels{/name}","releases_url":"https://api.github.com/repos/pattisdr/osf.io/releases{/id}","deployments_url":"https://api.github.com/repos/pattisdr/osf.io/deployments","created_at":"2015-05-19T18:33:09Z","updated_at":"2016-01-11T21:17:43Z","pushed_at":"2016-04-14T16:18:30Z","git_url":"git://github.com/pattisdr/osf.io.git","ssh_url":"git@github.com:pattisdr/osf.io.git","clone_url":"https://github.com/pattisdr/osf.io.git","svn_url":"https://github.com/pattisdr/osf.io","homepage":"http://osf.io","size":127897,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":0,"forks":1,"open_issues":0,"watchers":0,"default_branch":"develop"}},"base":{"label":"CenterForOpenScience:release/0.67.0","ref":"release/0.67.0","sha":"c9db277d42f389e1212f505e22312e7b2027867f","user":{"login":"CenterForOpenScience","id":3344584,"avatar_url":"https://avatars.githubusercontent.com/u/3344584?v=3","gravatar_id":"","url":"https://api.github.com/users/CenterForOpenScience","html_url":"https://github.com/CenterForOpenScience","followers_url":"https://api.github.com/users/CenterForOpenScience/followers","following_url":"https://api.github.com/users/CenterForOpenScience/following{/other_user}","gists_url":"https://api.github.com/users/CenterForOpenScience/gists{/gist_id}","starred_url":"https://api.github.com/users/CenterForOpenScience/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CenterForOpenScience/subscriptions","organizations_url":"https://api.github.com/users/CenterForOpenScience/orgs","repos_url":"https://api.github.com/users/CenterForOpenScience/repos","events_url":"https://api.github.com/users/CenterForOpenScience/events{/privacy}","received_events_url":"https://api.github.com/users/CenterForOpenScience/received_events","type":"Organization","site_admin":false},"repo":{"id":10199599,"name":"osf.io","full_name":"CenterForOpenScience/osf.io","owner":{"login":"CenterForOpenScience","id":3344584,"avatar_url":"https://avatars.githubusercontent.com/u/3344584?v=3","gravatar_id":"","url":"https://api.github.com/users/CenterForOpenScience","html_url":"https://github.com/CenterForOpenScience","followers_url":"https://api.github.com/users/CenterForOpenScience/followers","following_url":"https://api.github.com/users/CenterForOpenScience/following{/other_user}","gists_url":"https://api.github.com/users/CenterForOpenScience/gists{/gist_id}","starred_url":"https://api.github.com/users/CenterForOpenScience/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CenterForOpenScience/subscriptions","organizations_url":"https://api.github.com/users/CenterForOpenScience/orgs","repos_url":"https://api.github.com/users/CenterForOpenScience/repos","events_url":"https://api.github.com/users/CenterForOpenScience/events{/privacy}","received_events_url":"https://api.github.com/users/CenterForOpenScience/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/CenterForOpenScience/osf.io","description":"Facilitating Open Science","fork":false,"url":"https://api.github.com/repos/CenterForOpenScience/osf.io","forks_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/forks","keys_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/keys{/key_id}","collaborators_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/teams","hooks_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/hooks","issue_events_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/issues/events{/number}","events_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/events","assignees_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/assignees{/user}","branches_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/branches{/branch}","tags_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/tags","blobs_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/git/refs{/sha}","trees_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/git/trees{/sha}","statuses_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/statuses/{sha}","languages_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/languages","stargazers_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/stargazers","contributors_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/contributors","subscribers_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/subscribers","subscription_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/subscription","commits_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/commits{/sha}","git_commits_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/git/commits{/sha}","comments_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/comments{/number}","issue_comment_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/issues/comments{/number}","contents_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/contents/{+path}","compare_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/compare/{base}...{head}","merges_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/merges","archive_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/downloads","issues_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/issues{/number}","pulls_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls{/number}","milestones_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/milestones{/number}","notifications_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/labels{/name}","releases_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/releases{/id}","deployments_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/deployments","created_at":"2013-05-21T15:53:37Z","updated_at":"2016-04-11T14:54:41Z","pushed_at":"2016-04-14T16:20:15Z","git_url":"git://github.com/CenterForOpenScience/osf.io.git","ssh_url":"git@github.com:CenterForOpenScience/osf.io.git","clone_url":"https://github.com/CenterForOpenScience/osf.io.git","svn_url":"https://github.com/CenterForOpenScience/osf.io","homepage":"http://osf.io","size":272683,"stargazers_count":211,"watchers_count":211,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":162,"mirror_url":null,"open_issues_count":210,"forks":162,"open_issues":210,"watchers":211,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/5462"},"html":{"href":"https://github.com/CenterForOpenScience/osf.io/pull/5462"},"issue":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/issues/5462"},"comments":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/issues/5462/comments"},"review_comments":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/5462/comments"},"review_comment":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/5462/commits"},"statuses":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/statuses/9ec5afd2dde7ab78aafe546c68b13966b43c928f"}}}}