{"action":"created","comment":{"url":"https://api.github.com/repos/google/ggrc-core/pulls/comments/78540767","id":78540767,"diff_hunk":"@@ -0,0 +1,678 @@\n+# Copyright (C) 2016 Google Inc.\n+# Licensed under http://www.apache.org/licenses/LICENSE-2.0 <see LICENSE file>\n+\n+\"\"\"\n+Add lost revisions (SLOW!)\n+\n+Create Date: 2016-09-06 11:04:52.979211\n+\"\"\"\n+# This migration contains autogenerated code that makes linter unhappy\n+# pylint: disable=invalid-name, missing-docstring, redefined-variable-type\n+# pylint: disable=too-few-public-methods, bare-except, global-statement\n+\n+from datetime import datetime\n+\n+import sqlalchemy as sa\n+from alembic import op\n+\n+from ggrc import utils\n+\n+\n+# revision identifiers, used by Alembic.\n+revision = '343ed98643ee'\n+down_revision = '4450e7d1e441'\n+\n+\n+conn = None\n+meta = None\n+\n+\n+def setup():\n+  \"\"\"Setup DB connection and metadata.\"\"\"\n+  global conn, meta\n+\n+  conn = op.get_bind()\n+  meta = sa.MetaData(bind=conn)\n+  meta.reflect()\n+\n+  for class_ in globals().itervalues():\n+    if not hasattr(class_, '__table__'):\n+      continue\n+    try:\n+      class_.__table__ = meta.tables[class_.__table__]\n+    except KeyError:\n+      # Model comes from extension, that hasn't been enabled.\n+      # So we just ignore it.\n+      delattr(class_, '__table__')\n+\n+\n+def upgrade():\n+  \"\"\"Upgrade database schema and/or data, creating a new revision.\"\"\"\n+  setup()\n+\n+  now = datetime.now()\n+\n+  with conn.begin() as transaction:\n+    event_insert = meta.tables['events'].insert().values(\n+        action='BULK',\n+        created_at=now,\n+        updated_at=now,\n+    )\n+    event_id = conn.execute(event_insert).inserted_primary_key[0]\n+\n+    commit = False\n+    revision_insert = meta.tables['revisions'].insert()\n+\n+    for class_ in globals().itervalues():\n+      if not hasattr(class_, '__table__'):\n+        continue\n+\n+      cursor = class_.query_unrevisioned()\n+      while True:\n+        objects = cursor.fetchmany(1000)\n+        if not objects:\n+          break\n+        commit = True\n+        values = []\n+        for obj in objects:\n+          obj = class_(obj)\n+          if obj.created_at != obj.updated_at:\n+            action = 'modified'\n+          else:\n+            action = 'created'\n+          values.append({\n+              'event_id': event_id,\n+              'action': action,\n+              'resource_id': obj.id,\n+              'resource_type': class_.__name__,\n+              'content': utils.as_json(obj.log_json()),\n+              'source_type': getattr(obj, 'source_type', None),\n+              'source_id': getattr(obj, 'source_id', None),\n+              'destination_type': getattr(obj, 'destination_type', None),\n+              'destination_id': getattr(obj, 'destination_id', None),\n+              'created_at': obj.updated_at,\n+              'updated_at': obj.updated_at,","path":"src/ggrc/migrations/versions/20160906110452_343ed98643ee_add_lost_revisions.py","position":94,"original_position":94,"commit_id":"d75e4fdd193f17a1df07b2908651cd69b8577171","original_commit_id":"d75e4fdd193f17a1df07b2908651cd69b8577171","user":{"login":"Smotko","id":513444,"avatar_url":"https://avatars.githubusercontent.com/u/513444?v=3","gravatar_id":"","url":"https://api.github.com/users/Smotko","html_url":"https://github.com/Smotko","followers_url":"https://api.github.com/users/Smotko/followers","following_url":"https://api.github.com/users/Smotko/following{/other_user}","gists_url":"https://api.github.com/users/Smotko/gists{/gist_id}","starred_url":"https://api.github.com/users/Smotko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Smotko/subscriptions","organizations_url":"https://api.github.com/users/Smotko/orgs","repos_url":"https://api.github.com/users/Smotko/repos","events_url":"https://api.github.com/users/Smotko/events{/privacy}","received_events_url":"https://api.github.com/users/Smotko/received_events","type":"User","site_admin":false},"body":"I believe we will need to add `modified_by_id` here as well otherwise we might have issues on the frontend. You can use the object's `modified_by_id` field for this. ","created_at":"2016-09-13T11:31:44Z","updated_at":"2016-09-13T11:31:44Z","html_url":"https://github.com/google/ggrc-core/pull/4374#discussion_r78540767","pull_request_url":"https://api.github.com/repos/google/ggrc-core/pulls/4374","_links":{"self":{"href":"https://api.github.com/repos/google/ggrc-core/pulls/comments/78540767"},"html":{"href":"https://github.com/google/ggrc-core/pull/4374#discussion_r78540767"},"pull_request":{"href":"https://api.github.com/repos/google/ggrc-core/pulls/4374"}}},"pull_request":{"url":"https://api.github.com/repos/google/ggrc-core/pulls/4374","id":84669792,"html_url":"https://github.com/google/ggrc-core/pull/4374","diff_url":"https://github.com/google/ggrc-core/pull/4374.diff","patch_url":"https://github.com/google/ggrc-core/pull/4374.patch","issue_url":"https://api.github.com/repos/google/ggrc-core/issues/4374","number":4374,"state":"open","locked":false,"title":"QUICK-FIX Add migration to recover lost revisions","user":{"login":"kr41","id":961059,"avatar_url":"https://avatars.githubusercontent.com/u/961059?v=3","gravatar_id":"","url":"https://api.github.com/users/kr41","html_url":"https://github.com/kr41","followers_url":"https://api.github.com/users/kr41/followers","following_url":"https://api.github.com/users/kr41/following{/other_user}","gists_url":"https://api.github.com/users/kr41/gists{/gist_id}","starred_url":"https://api.github.com/users/kr41/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kr41/subscriptions","organizations_url":"https://api.github.com/users/kr41/orgs","repos_url":"https://api.github.com/users/kr41/repos","events_url":"https://api.github.com/users/kr41/events{/privacy}","received_events_url":"https://api.github.com/users/kr41/received_events","type":"User","site_admin":false},"body":"There is a lot of objects in the DB that have no revisions. This migration recovers them.","created_at":"2016-09-09T15:24:50Z","updated_at":"2016-09-13T11:31:44Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5cb8061b1b95c611bb52c7967f5cd64c4053d1b0","assignee":{"login":"Smotko","id":513444,"avatar_url":"https://avatars.githubusercontent.com/u/513444?v=3","gravatar_id":"","url":"https://api.github.com/users/Smotko","html_url":"https://github.com/Smotko","followers_url":"https://api.github.com/users/Smotko/followers","following_url":"https://api.github.com/users/Smotko/following{/other_user}","gists_url":"https://api.github.com/users/Smotko/gists{/gist_id}","starred_url":"https://api.github.com/users/Smotko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Smotko/subscriptions","organizations_url":"https://api.github.com/users/Smotko/orgs","repos_url":"https://api.github.com/users/Smotko/repos","events_url":"https://api.github.com/users/Smotko/events{/privacy}","received_events_url":"https://api.github.com/users/Smotko/received_events","type":"User","site_admin":false},"assignees":[{"login":"Smotko","id":513444,"avatar_url":"https://avatars.githubusercontent.com/u/513444?v=3","gravatar_id":"","url":"https://api.github.com/users/Smotko","html_url":"https://github.com/Smotko","followers_url":"https://api.github.com/users/Smotko/followers","following_url":"https://api.github.com/users/Smotko/following{/other_user}","gists_url":"https://api.github.com/users/Smotko/gists{/gist_id}","starred_url":"https://api.github.com/users/Smotko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Smotko/subscriptions","organizations_url":"https://api.github.com/users/Smotko/orgs","repos_url":"https://api.github.com/users/Smotko/repos","events_url":"https://api.github.com/users/Smotko/events{/privacy}","received_events_url":"https://api.github.com/users/Smotko/received_events","type":"User","site_admin":false}],"milestone":{"url":"https://api.github.com/repos/google/ggrc-core/milestones/21","html_url":"https://github.com/google/ggrc-core/milestones/0.9.7-Quince","labels_url":"https://api.github.com/repos/google/ggrc-core/milestones/21/labels","id":1845906,"number":21,"title":"0.9.7-Quince","description":"","creator":{"login":"Smotko","id":513444,"avatar_url":"https://avatars.githubusercontent.com/u/513444?v=3","gravatar_id":"","url":"https://api.github.com/users/Smotko","html_url":"https://github.com/Smotko","followers_url":"https://api.github.com/users/Smotko/followers","following_url":"https://api.github.com/users/Smotko/following{/other_user}","gists_url":"https://api.github.com/users/Smotko/gists{/gist_id}","starred_url":"https://api.github.com/users/Smotko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Smotko/subscriptions","organizations_url":"https://api.github.com/users/Smotko/orgs","repos_url":"https://api.github.com/users/Smotko/repos","events_url":"https://api.github.com/users/Smotko/events{/privacy}","received_events_url":"https://api.github.com/users/Smotko/received_events","type":"User","site_admin":false},"open_issues":15,"closed_issues":305,"state":"open","created_at":"2016-06-23T17:56:25Z","updated_at":"2016-09-13T09:27:04Z","due_on":"2016-08-14T22:00:00Z","closed_at":null},"commits_url":"https://api.github.com/repos/google/ggrc-core/pulls/4374/commits","review_comments_url":"https://api.github.com/repos/google/ggrc-core/pulls/4374/comments","review_comment_url":"https://api.github.com/repos/google/ggrc-core/pulls/comments{/number}","comments_url":"https://api.github.com/repos/google/ggrc-core/issues/4374/comments","statuses_url":"https://api.github.com/repos/google/ggrc-core/statuses/d75e4fdd193f17a1df07b2908651cd69b8577171","head":{"label":"kr41:quickfix-add-lost-revisions","ref":"quickfix-add-lost-revisions","sha":"d75e4fdd193f17a1df07b2908651cd69b8577171","user":{"login":"kr41","id":961059,"avatar_url":"https://avatars.githubusercontent.com/u/961059?v=3","gravatar_id":"","url":"https://api.github.com/users/kr41","html_url":"https://github.com/kr41","followers_url":"https://api.github.com/users/kr41/followers","following_url":"https://api.github.com/users/kr41/following{/other_user}","gists_url":"https://api.github.com/users/kr41/gists{/gist_id}","starred_url":"https://api.github.com/users/kr41/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kr41/subscriptions","organizations_url":"https://api.github.com/users/kr41/orgs","repos_url":"https://api.github.com/users/kr41/repos","events_url":"https://api.github.com/users/kr41/events{/privacy}","received_events_url":"https://api.github.com/users/kr41/received_events","type":"User","site_admin":false},"repo":{"id":63245784,"name":"ggrc-core","full_name":"kr41/ggrc-core","owner":{"login":"kr41","id":961059,"avatar_url":"https://avatars.githubusercontent.com/u/961059?v=3","gravatar_id":"","url":"https://api.github.com/users/kr41","html_url":"https://github.com/kr41","followers_url":"https://api.github.com/users/kr41/followers","following_url":"https://api.github.com/users/kr41/following{/other_user}","gists_url":"https://api.github.com/users/kr41/gists{/gist_id}","starred_url":"https://api.github.com/users/kr41/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kr41/subscriptions","organizations_url":"https://api.github.com/users/kr41/orgs","repos_url":"https://api.github.com/users/kr41/repos","events_url":"https://api.github.com/users/kr41/events{/privacy}","received_events_url":"https://api.github.com/users/kr41/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/kr41/ggrc-core","description":"GGRC Core","fork":true,"url":"https://api.github.com/repos/kr41/ggrc-core","forks_url":"https://api.github.com/repos/kr41/ggrc-core/forks","keys_url":"https://api.github.com/repos/kr41/ggrc-core/keys{/key_id}","collaborators_url":"https://api.github.com/repos/kr41/ggrc-core/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/kr41/ggrc-core/teams","hooks_url":"https://api.github.com/repos/kr41/ggrc-core/hooks","issue_events_url":"https://api.github.com/repos/kr41/ggrc-core/issues/events{/number}","events_url":"https://api.github.com/repos/kr41/ggrc-core/events","assignees_url":"https://api.github.com/repos/kr41/ggrc-core/assignees{/user}","branches_url":"https://api.github.com/repos/kr41/ggrc-core/branches{/branch}","tags_url":"https://api.github.com/repos/kr41/ggrc-core/tags","blobs_url":"https://api.github.com/repos/kr41/ggrc-core/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/kr41/ggrc-core/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/kr41/ggrc-core/git/refs{/sha}","trees_url":"https://api.github.com/repos/kr41/ggrc-core/git/trees{/sha}","statuses_url":"https://api.github.com/repos/kr41/ggrc-core/statuses/{sha}","languages_url":"https://api.github.com/repos/kr41/ggrc-core/languages","stargazers_url":"https://api.github.com/repos/kr41/ggrc-core/stargazers","contributors_url":"https://api.github.com/repos/kr41/ggrc-core/contributors","subscribers_url":"https://api.github.com/repos/kr41/ggrc-core/subscribers","subscription_url":"https://api.github.com/repos/kr41/ggrc-core/subscription","commits_url":"https://api.github.com/repos/kr41/ggrc-core/commits{/sha}","git_commits_url":"https://api.github.com/repos/kr41/ggrc-core/git/commits{/sha}","comments_url":"https://api.github.com/repos/kr41/ggrc-core/comments{/number}","issue_comment_url":"https://api.github.com/repos/kr41/ggrc-core/issues/comments{/number}","contents_url":"https://api.github.com/repos/kr41/ggrc-core/contents/{+path}","compare_url":"https://api.github.com/repos/kr41/ggrc-core/compare/{base}...{head}","merges_url":"https://api.github.com/repos/kr41/ggrc-core/merges","archive_url":"https://api.github.com/repos/kr41/ggrc-core/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/kr41/ggrc-core/downloads","issues_url":"https://api.github.com/repos/kr41/ggrc-core/issues{/number}","pulls_url":"https://api.github.com/repos/kr41/ggrc-core/pulls{/number}","milestones_url":"https://api.github.com/repos/kr41/ggrc-core/milestones{/number}","notifications_url":"https://api.github.com/repos/kr41/ggrc-core/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/kr41/ggrc-core/labels{/name}","releases_url":"https://api.github.com/repos/kr41/ggrc-core/releases{/id}","deployments_url":"https://api.github.com/repos/kr41/ggrc-core/deployments","created_at":"2016-07-13T12:55:09Z","updated_at":"2016-07-13T12:55:15Z","pushed_at":"2016-09-13T11:21:40Z","git_url":"git://github.com/kr41/ggrc-core.git","ssh_url":"git@github.com:kr41/ggrc-core.git","clone_url":"https://github.com/kr41/ggrc-core.git","svn_url":"https://github.com/kr41/ggrc-core","homepage":null,"size":54344,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"develop"}},"base":{"label":"google:develop","ref":"develop","sha":"70ff2e0c33ffe830f26bd9405dfd16bf014408e2","user":{"login":"google","id":1342004,"avatar_url":"https://avatars.githubusercontent.com/u/1342004?v=3","gravatar_id":"","url":"https://api.github.com/users/google","html_url":"https://github.com/google","followers_url":"https://api.github.com/users/google/followers","following_url":"https://api.github.com/users/google/following{/other_user}","gists_url":"https://api.github.com/users/google/gists{/gist_id}","starred_url":"https://api.github.com/users/google/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/google/subscriptions","organizations_url":"https://api.github.com/users/google/orgs","repos_url":"https://api.github.com/users/google/repos","events_url":"https://api.github.com/users/google/events{/privacy}","received_events_url":"https://api.github.com/users/google/received_events","type":"Organization","site_admin":false},"repo":{"id":9304637,"name":"ggrc-core","full_name":"google/ggrc-core","owner":{"login":"google","id":1342004,"avatar_url":"https://avatars.githubusercontent.com/u/1342004?v=3","gravatar_id":"","url":"https://api.github.com/users/google","html_url":"https://github.com/google","followers_url":"https://api.github.com/users/google/followers","following_url":"https://api.github.com/users/google/following{/other_user}","gists_url":"https://api.github.com/users/google/gists{/gist_id}","starred_url":"https://api.github.com/users/google/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/google/subscriptions","organizations_url":"https://api.github.com/users/google/orgs","repos_url":"https://api.github.com/users/google/repos","events_url":"https://api.github.com/users/google/events{/privacy}","received_events_url":"https://api.github.com/users/google/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/google/ggrc-core","description":"GGRC Core","fork":false,"url":"https://api.github.com/repos/google/ggrc-core","forks_url":"https://api.github.com/repos/google/ggrc-core/forks","keys_url":"https://api.github.com/repos/google/ggrc-core/keys{/key_id}","collaborators_url":"https://api.github.com/repos/google/ggrc-core/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/google/ggrc-core/teams","hooks_url":"https://api.github.com/repos/google/ggrc-core/hooks","issue_events_url":"https://api.github.com/repos/google/ggrc-core/issues/events{/number}","events_url":"https://api.github.com/repos/google/ggrc-core/events","assignees_url":"https://api.github.com/repos/google/ggrc-core/assignees{/user}","branches_url":"https://api.github.com/repos/google/ggrc-core/branches{/branch}","tags_url":"https://api.github.com/repos/google/ggrc-core/tags","blobs_url":"https://api.github.com/repos/google/ggrc-core/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/google/ggrc-core/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/google/ggrc-core/git/refs{/sha}","trees_url":"https://api.github.com/repos/google/ggrc-core/git/trees{/sha}","statuses_url":"https://api.github.com/repos/google/ggrc-core/statuses/{sha}","languages_url":"https://api.github.com/repos/google/ggrc-core/languages","stargazers_url":"https://api.github.com/repos/google/ggrc-core/stargazers","contributors_url":"https://api.github.com/repos/google/ggrc-core/contributors","subscribers_url":"https://api.github.com/repos/google/ggrc-core/subscribers","subscription_url":"https://api.github.com/repos/google/ggrc-core/subscription","commits_url":"https://api.github.com/repos/google/ggrc-core/commits{/sha}","git_commits_url":"https://api.github.com/repos/google/ggrc-core/git/commits{/sha}","comments_url":"https://api.github.com/repos/google/ggrc-core/comments{/number}","issue_comment_url":"https://api.github.com/repos/google/ggrc-core/issues/comments{/number}","contents_url":"https://api.github.com/repos/google/ggrc-core/contents/{+path}","compare_url":"https://api.github.com/repos/google/ggrc-core/compare/{base}...{head}","merges_url":"https://api.github.com/repos/google/ggrc-core/merges","archive_url":"https://api.github.com/repos/google/ggrc-core/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/google/ggrc-core/downloads","issues_url":"https://api.github.com/repos/google/ggrc-core/issues{/number}","pulls_url":"https://api.github.com/repos/google/ggrc-core/pulls{/number}","milestones_url":"https://api.github.com/repos/google/ggrc-core/milestones{/number}","notifications_url":"https://api.github.com/repos/google/ggrc-core/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/google/ggrc-core/labels{/name}","releases_url":"https://api.github.com/repos/google/ggrc-core/releases{/id}","deployments_url":"https://api.github.com/repos/google/ggrc-core/deployments","created_at":"2013-04-08T19:16:28Z","updated_at":"2016-09-05T22:52:34Z","pushed_at":"2016-09-13T10:49:24Z","git_url":"git://github.com/google/ggrc-core.git","ssh_url":"git@github.com:google/ggrc-core.git","clone_url":"https://github.com/google/ggrc-core.git","svn_url":"https://github.com/google/ggrc-core","homepage":null,"size":65143,"stargazers_count":129,"watchers_count":129,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":100,"mirror_url":null,"open_issues_count":21,"forks":100,"open_issues":21,"watchers":129,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/google/ggrc-core/pulls/4374"},"html":{"href":"https://github.com/google/ggrc-core/pull/4374"},"issue":{"href":"https://api.github.com/repos/google/ggrc-core/issues/4374"},"comments":{"href":"https://api.github.com/repos/google/ggrc-core/issues/4374/comments"},"review_comments":{"href":"https://api.github.com/repos/google/ggrc-core/pulls/4374/comments"},"review_comment":{"href":"https://api.github.com/repos/google/ggrc-core/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/google/ggrc-core/pulls/4374/commits"},"statuses":{"href":"https://api.github.com/repos/google/ggrc-core/statuses/d75e4fdd193f17a1df07b2908651cd69b8577171"}}}}
{"actor":{"display_login":"Smotko"}}