{"action":"created","comment":{"url":"https://api.github.com/repos/etianen/django-reversion/pulls/comments/65095538","id":65095538,"diff_hunk":"@@ -0,0 +1,52 @@\n+\n+from django.db.models import Func, fields\n+\n+\n+class ReversionCast(Func):\n+    \"\"\"\n+    Coerce an expression to a new field type.\n+    \"\"\"\n+    function = 'CAST'\n+    template = '%(function)s(%(expressions)s AS %(db_type)s)'\n+\n+    override_mysql_types = {\n+        'AutoField': 'signed',\n+        'CharField': 'char',\n+        'FloatField': 'signed',\n+        'DecimalField': 'decimal(%(max_digits)s, %(decimal_places)s)',\n+        'IntegerField': 'signed',\n+        'BigIntegerField': 'signed',\n+        'OneToOneField': 'signed',\n+        'PositiveIntegerField': 'unsigned',\n+        'PositiveSmallIntegerField': 'unsigned',\n+        'SlugField': 'char',\n+        'SmallIntegerField': 'signed',\n+    }\n+\n+    override_postgresql_types = {\n+        'AutoField': 'integer',\n+    }\n+\n+    def __init__(self, expression, output_field):\n+        super(ReversionCast, self).__init__(expression, output_field=output_field)\n+\n+    def as_sql(self, compiler, connection, **extra_context):\n+        if 'db_type' not in self.extra:\n+            self.extra['db_type'] = self._output_field.db_type(connection)\n+        return super(ReversionCast, self).as_sql(compiler, connection, **extra_context)\n+\n+    def as_mysql(self, compiler, connection):\n+        output_field_class = self._output_field.get_internal_type()\n+        if output_field_class in self.override_mysql_types:\n+            self.extra['db_type'] = self.override_mysql_types[output_field_class]\n+        template = self.template\n+        if output_field_class == 'CharField':\n+            template = '%(function)s(%(expressions)s AS %(db_type)s) COLLATE ''utf8_unicode_ci'''\n+        return self.as_sql(compiler, connection, template=template)\n+\n+    def as_postgresql(self, compiler, connection):\n+        output_field_class = self._output_field.get_internal_type()\n+        if output_field_class in self.override_postgresql_types:\n+            self.extra['db_type'] = self.override_postgresql_types[output_field_class]\n+        # CAST would be valid too, but the :: shortcut syntax is more readable.\n+        return self.as_sql(compiler, connection, template='%(expressions)s::%(db_type)s')","path":"src/reversion/functions.py","position":52,"original_position":52,"commit_id":"1c97b0bd46172088ff7cf66333c2920fd4a93e81","original_commit_id":"1c97b0bd46172088ff7cf66333c2920fd4a93e81","user":{"login":"etianen","id":148744,"avatar_url":"https://avatars.githubusercontent.com/u/148744?v=3","gravatar_id":"","url":"https://api.github.com/users/etianen","html_url":"https://github.com/etianen","followers_url":"https://api.github.com/users/etianen/followers","following_url":"https://api.github.com/users/etianen/following{/other_user}","gists_url":"https://api.github.com/users/etianen/gists{/gist_id}","starred_url":"https://api.github.com/users/etianen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/etianen/subscriptions","organizations_url":"https://api.github.com/users/etianen/orgs","repos_url":"https://api.github.com/users/etianen/repos","events_url":"https://api.github.com/users/etianen/events{/privacy}","received_events_url":"https://api.github.com/users/etianen/received_events","type":"User","site_admin":false},"body":"Hold fire for the time being, I've almost got a solution that supports common database setups for in-database joins.","created_at":"2016-05-30T17:42:00Z","updated_at":"2016-05-30T17:42:00Z","html_url":"https://github.com/etianen/django-reversion/pull/521#discussion_r65095538","pull_request_url":"https://api.github.com/repos/etianen/django-reversion/pulls/521","_links":{"self":{"href":"https://api.github.com/repos/etianen/django-reversion/pulls/comments/65095538"},"html":{"href":"https://github.com/etianen/django-reversion/pull/521#discussion_r65095538"},"pull_request":{"href":"https://api.github.com/repos/etianen/django-reversion/pulls/521"}}},"pull_request":{"url":"https://api.github.com/repos/etianen/django-reversion/pulls/521","id":70109002,"html_url":"https://github.com/etianen/django-reversion/pull/521","diff_url":"https://github.com/etianen/django-reversion/pull/521.diff","patch_url":"https://github.com/etianen/django-reversion/pull/521.patch","issue_url":"https://api.github.com/repos/etianen/django-reversion/issues/521","number":521,"state":"open","locked":false,"title":"Change Object_Id to Char and Index","user":{"login":"mshannon1123","id":5375321,"avatar_url":"https://avatars.githubusercontent.com/u/5375321?v=3","gravatar_id":"","url":"https://api.github.com/users/mshannon1123","html_url":"https://github.com/mshannon1123","followers_url":"https://api.github.com/users/mshannon1123/followers","following_url":"https://api.github.com/users/mshannon1123/following{/other_user}","gists_url":"https://api.github.com/users/mshannon1123/gists{/gist_id}","starred_url":"https://api.github.com/users/mshannon1123/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mshannon1123/subscriptions","organizations_url":"https://api.github.com/users/mshannon1123/orgs","repos_url":"https://api.github.com/users/mshannon1123/repos","events_url":"https://api.github.com/users/mshannon1123/events{/privacy}","received_events_url":"https://api.github.com/users/mshannon1123/received_events","type":"User","site_admin":false},"body":"- Remove object_id_int\r\n- Combination index for content_type and object_id for performance","created_at":"2016-05-15T01:21:58Z","updated_at":"2016-05-30T17:42:00Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7e91ba25b53044d0c28e514256d12340a042c0f5","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/etianen/django-reversion/pulls/521/commits","review_comments_url":"https://api.github.com/repos/etianen/django-reversion/pulls/521/comments","review_comment_url":"https://api.github.com/repos/etianen/django-reversion/pulls/comments{/number}","comments_url":"https://api.github.com/repos/etianen/django-reversion/issues/521/comments","statuses_url":"https://api.github.com/repos/etianen/django-reversion/statuses/1c97b0bd46172088ff7cf66333c2920fd4a93e81","head":{"label":"urbn:index_optimization","ref":"index_optimization","sha":"1c97b0bd46172088ff7cf66333c2920fd4a93e81","user":{"login":"urbn","id":4368103,"avatar_url":"https://avatars.githubusercontent.com/u/4368103?v=3","gravatar_id":"","url":"https://api.github.com/users/urbn","html_url":"https://github.com/urbn","followers_url":"https://api.github.com/users/urbn/followers","following_url":"https://api.github.com/users/urbn/following{/other_user}","gists_url":"https://api.github.com/users/urbn/gists{/gist_id}","starred_url":"https://api.github.com/users/urbn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/urbn/subscriptions","organizations_url":"https://api.github.com/users/urbn/orgs","repos_url":"https://api.github.com/users/urbn/repos","events_url":"https://api.github.com/users/urbn/events{/privacy}","received_events_url":"https://api.github.com/users/urbn/received_events","type":"Organization","site_admin":false},"repo":{"id":56316233,"name":"django-reversion","full_name":"urbn/django-reversion","owner":{"login":"urbn","id":4368103,"avatar_url":"https://avatars.githubusercontent.com/u/4368103?v=3","gravatar_id":"","url":"https://api.github.com/users/urbn","html_url":"https://github.com/urbn","followers_url":"https://api.github.com/users/urbn/followers","following_url":"https://api.github.com/users/urbn/following{/other_user}","gists_url":"https://api.github.com/users/urbn/gists{/gist_id}","starred_url":"https://api.github.com/users/urbn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/urbn/subscriptions","organizations_url":"https://api.github.com/users/urbn/orgs","repos_url":"https://api.github.com/users/urbn/repos","events_url":"https://api.github.com/users/urbn/events{/privacy}","received_events_url":"https://api.github.com/users/urbn/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/urbn/django-reversion","description":"An extension to the Django web framework that provides comprehensive version control facilities.","fork":true,"url":"https://api.github.com/repos/urbn/django-reversion","forks_url":"https://api.github.com/repos/urbn/django-reversion/forks","keys_url":"https://api.github.com/repos/urbn/django-reversion/keys{/key_id}","collaborators_url":"https://api.github.com/repos/urbn/django-reversion/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/urbn/django-reversion/teams","hooks_url":"https://api.github.com/repos/urbn/django-reversion/hooks","issue_events_url":"https://api.github.com/repos/urbn/django-reversion/issues/events{/number}","events_url":"https://api.github.com/repos/urbn/django-reversion/events","assignees_url":"https://api.github.com/repos/urbn/django-reversion/assignees{/user}","branches_url":"https://api.github.com/repos/urbn/django-reversion/branches{/branch}","tags_url":"https://api.github.com/repos/urbn/django-reversion/tags","blobs_url":"https://api.github.com/repos/urbn/django-reversion/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/urbn/django-reversion/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/urbn/django-reversion/git/refs{/sha}","trees_url":"https://api.github.com/repos/urbn/django-reversion/git/trees{/sha}","statuses_url":"https://api.github.com/repos/urbn/django-reversion/statuses/{sha}","languages_url":"https://api.github.com/repos/urbn/django-reversion/languages","stargazers_url":"https://api.github.com/repos/urbn/django-reversion/stargazers","contributors_url":"https://api.github.com/repos/urbn/django-reversion/contributors","subscribers_url":"https://api.github.com/repos/urbn/django-reversion/subscribers","subscription_url":"https://api.github.com/repos/urbn/django-reversion/subscription","commits_url":"https://api.github.com/repos/urbn/django-reversion/commits{/sha}","git_commits_url":"https://api.github.com/repos/urbn/django-reversion/git/commits{/sha}","comments_url":"https://api.github.com/repos/urbn/django-reversion/comments{/number}","issue_comment_url":"https://api.github.com/repos/urbn/django-reversion/issues/comments{/number}","contents_url":"https://api.github.com/repos/urbn/django-reversion/contents/{+path}","compare_url":"https://api.github.com/repos/urbn/django-reversion/compare/{base}...{head}","merges_url":"https://api.github.com/repos/urbn/django-reversion/merges","archive_url":"https://api.github.com/repos/urbn/django-reversion/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/urbn/django-reversion/downloads","issues_url":"https://api.github.com/repos/urbn/django-reversion/issues{/number}","pulls_url":"https://api.github.com/repos/urbn/django-reversion/pulls{/number}","milestones_url":"https://api.github.com/repos/urbn/django-reversion/milestones{/number}","notifications_url":"https://api.github.com/repos/urbn/django-reversion/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/urbn/django-reversion/labels{/name}","releases_url":"https://api.github.com/repos/urbn/django-reversion/releases{/id}","deployments_url":"https://api.github.com/repos/urbn/django-reversion/deployments","created_at":"2016-04-15T11:48:06Z","updated_at":"2016-04-15T11:48:06Z","pushed_at":"2016-05-16T22:09:29Z","git_url":"git://github.com/urbn/django-reversion.git","ssh_url":"git@github.com:urbn/django-reversion.git","clone_url":"https://github.com/urbn/django-reversion.git","svn_url":"https://github.com/urbn/django-reversion","homepage":"http://github.com/etianen/django-reversion","size":1192,"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":"master"}},"base":{"label":"etianen:master","ref":"master","sha":"e32232b0690ff69d3db1ebacc17df5e88b73c1db","user":{"login":"etianen","id":148744,"avatar_url":"https://avatars.githubusercontent.com/u/148744?v=3","gravatar_id":"","url":"https://api.github.com/users/etianen","html_url":"https://github.com/etianen","followers_url":"https://api.github.com/users/etianen/followers","following_url":"https://api.github.com/users/etianen/following{/other_user}","gists_url":"https://api.github.com/users/etianen/gists{/gist_id}","starred_url":"https://api.github.com/users/etianen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/etianen/subscriptions","organizations_url":"https://api.github.com/users/etianen/orgs","repos_url":"https://api.github.com/users/etianen/repos","events_url":"https://api.github.com/users/etianen/events{/privacy}","received_events_url":"https://api.github.com/users/etianen/received_events","type":"User","site_admin":false},"repo":{"id":695611,"name":"django-reversion","full_name":"etianen/django-reversion","owner":{"login":"etianen","id":148744,"avatar_url":"https://avatars.githubusercontent.com/u/148744?v=3","gravatar_id":"","url":"https://api.github.com/users/etianen","html_url":"https://github.com/etianen","followers_url":"https://api.github.com/users/etianen/followers","following_url":"https://api.github.com/users/etianen/following{/other_user}","gists_url":"https://api.github.com/users/etianen/gists{/gist_id}","starred_url":"https://api.github.com/users/etianen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/etianen/subscriptions","organizations_url":"https://api.github.com/users/etianen/orgs","repos_url":"https://api.github.com/users/etianen/repos","events_url":"https://api.github.com/users/etianen/events{/privacy}","received_events_url":"https://api.github.com/users/etianen/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/etianen/django-reversion","description":"An extension to the Django web framework that provides comprehensive version control facilities.","fork":false,"url":"https://api.github.com/repos/etianen/django-reversion","forks_url":"https://api.github.com/repos/etianen/django-reversion/forks","keys_url":"https://api.github.com/repos/etianen/django-reversion/keys{/key_id}","collaborators_url":"https://api.github.com/repos/etianen/django-reversion/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/etianen/django-reversion/teams","hooks_url":"https://api.github.com/repos/etianen/django-reversion/hooks","issue_events_url":"https://api.github.com/repos/etianen/django-reversion/issues/events{/number}","events_url":"https://api.github.com/repos/etianen/django-reversion/events","assignees_url":"https://api.github.com/repos/etianen/django-reversion/assignees{/user}","branches_url":"https://api.github.com/repos/etianen/django-reversion/branches{/branch}","tags_url":"https://api.github.com/repos/etianen/django-reversion/tags","blobs_url":"https://api.github.com/repos/etianen/django-reversion/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/etianen/django-reversion/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/etianen/django-reversion/git/refs{/sha}","trees_url":"https://api.github.com/repos/etianen/django-reversion/git/trees{/sha}","statuses_url":"https://api.github.com/repos/etianen/django-reversion/statuses/{sha}","languages_url":"https://api.github.com/repos/etianen/django-reversion/languages","stargazers_url":"https://api.github.com/repos/etianen/django-reversion/stargazers","contributors_url":"https://api.github.com/repos/etianen/django-reversion/contributors","subscribers_url":"https://api.github.com/repos/etianen/django-reversion/subscribers","subscription_url":"https://api.github.com/repos/etianen/django-reversion/subscription","commits_url":"https://api.github.com/repos/etianen/django-reversion/commits{/sha}","git_commits_url":"https://api.github.com/repos/etianen/django-reversion/git/commits{/sha}","comments_url":"https://api.github.com/repos/etianen/django-reversion/comments{/number}","issue_comment_url":"https://api.github.com/repos/etianen/django-reversion/issues/comments{/number}","contents_url":"https://api.github.com/repos/etianen/django-reversion/contents/{+path}","compare_url":"https://api.github.com/repos/etianen/django-reversion/compare/{base}...{head}","merges_url":"https://api.github.com/repos/etianen/django-reversion/merges","archive_url":"https://api.github.com/repos/etianen/django-reversion/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/etianen/django-reversion/downloads","issues_url":"https://api.github.com/repos/etianen/django-reversion/issues{/number}","pulls_url":"https://api.github.com/repos/etianen/django-reversion/pulls{/number}","milestones_url":"https://api.github.com/repos/etianen/django-reversion/milestones{/number}","notifications_url":"https://api.github.com/repos/etianen/django-reversion/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/etianen/django-reversion/labels{/name}","releases_url":"https://api.github.com/repos/etianen/django-reversion/releases{/id}","deployments_url":"https://api.github.com/repos/etianen/django-reversion/deployments","created_at":"2010-05-31T15:32:25Z","updated_at":"2016-05-30T05:42:35Z","pushed_at":"2016-05-30T17:35:13Z","git_url":"git://github.com/etianen/django-reversion.git","ssh_url":"git@github.com:etianen/django-reversion.git","clone_url":"https://github.com/etianen/django-reversion.git","svn_url":"https://github.com/etianen/django-reversion","homepage":"http://github.com/etianen/django-reversion","size":1739,"stargazers_count":1569,"watchers_count":1569,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":295,"mirror_url":null,"open_issues_count":26,"forks":295,"open_issues":26,"watchers":1569,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/etianen/django-reversion/pulls/521"},"html":{"href":"https://github.com/etianen/django-reversion/pull/521"},"issue":{"href":"https://api.github.com/repos/etianen/django-reversion/issues/521"},"comments":{"href":"https://api.github.com/repos/etianen/django-reversion/issues/521/comments"},"review_comments":{"href":"https://api.github.com/repos/etianen/django-reversion/pulls/521/comments"},"review_comment":{"href":"https://api.github.com/repos/etianen/django-reversion/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/etianen/django-reversion/pulls/521/commits"},"statuses":{"href":"https://api.github.com/repos/etianen/django-reversion/statuses/1c97b0bd46172088ff7cf66333c2920fd4a93e81"}}}}
{"actor":{"display_login":"etianen"}}