GitHub PullRequestReviewCommentEvent at 2014-10-15 11:05:02
Repository: activerecord-databasevalidations
Actor: jduff
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/pulls/comments/18886854","id":18886854,"diff_hunk":"@@ -1 +1,45 @@\n-# Activerecord::DatabaseValidations\n+# ActiveRecord::DatabaseValidations\n+\n+Add validations to your ActiveRecord models based on your database constraints.\n+\n+## Installation\n+\n+Add this line to your application's Gemfile:\n+\n+    gem 'activerecord-databasevalidations'\n+\n+And then execute:\n+\n+    $ bundle\n+\n+Or install it yourself as:\n+\n+    $ gem install activerecord-databasevalidations\n+\n+## Usage\n+\n+You can use ActiveModel's `validates` method to define what fields you want\n+to validate based on the database constraints.\n+\n+``` ruby\n+class Foo < ActiveRecord::Base\n+  validates :string_field, :boolean_field, database_constraints: true\n+  validates :string_field, database_constraints: { constraints: [:size, :not_null] }","path":"README.md","position":28,"original_position":28,"commit_id":"c22e4f8261e065e7ca2a7776634832ce775c7f00","original_commit_id":"c22e4f8261e065e7ca2a7776634832ce775c7f00","user":{"login":"jduff","id":441,"avatar_url":"https://avatars.githubusercontent.com/u/441?v=2","gravatar_id":"","url":"https://api.github.com/users/jduff","html_url":"https://github.com/jduff","followers_url":"https://api.github.com/users/jduff/followers","following_url":"https://api.github.com/users/jduff/following{/other_user}","gists_url":"https://api.github.com/users/jduff/gists{/gist_id}","starred_url":"https://api.github.com/users/jduff/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jduff/subscriptions","organizations_url":"https://api.github.com/users/jduff/orgs","repos_url":"https://api.github.com/users/jduff/repos","events_url":"https://api.github.com/users/jduff/events{/privacy}","received_events_url":"https://api.github.com/users/jduff/received_events","type":"User","site_admin":false},"body":"Is the extra constraints key necessary? Couldn't we just pass the array of constraints here?","created_at":"2014-10-15T11:05:02Z","updated_at":"2014-10-15T11:05:02Z","html_url":"https://github.com/wvanbergen/activerecord-databasevalidations/pull/2#discussion_r18886854","pull_request_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/pulls/2","_links":{"self":{"href":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/pulls/comments/18886854"},"html":{"href":"https://github.com/wvanbergen/activerecord-databasevalidations/pull/2#discussion_r18886854"},"pull_request":{"href":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/pulls/2"}}},"pull_request":{"url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/pulls/2","id":22675702,"html_url":"https://github.com/wvanbergen/activerecord-databasevalidations/pull/2","diff_url":"https://github.com/wvanbergen/activerecord-databasevalidations/pull/2.diff","patch_url":"https://github.com/wvanbergen/activerecord-databasevalidations/pull/2.patch","issue_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/issues/2","number":2,"state":"open","locked":false,"title":"Initial implementation","user":{"login":"wvanbergen","id":15870,"avatar_url":"https://avatars.githubusercontent.com/u/15870?v=2","gravatar_id":"","url":"https://api.github.com/users/wvanbergen","html_url":"https://github.com/wvanbergen","followers_url":"https://api.github.com/users/wvanbergen/followers","following_url":"https://api.github.com/users/wvanbergen/following{/other_user}","gists_url":"https://api.github.com/users/wvanbergen/gists{/gist_id}","starred_url":"https://api.github.com/users/wvanbergen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wvanbergen/subscriptions","organizations_url":"https://api.github.com/users/wvanbergen/orgs","repos_url":"https://api.github.com/users/wvanbergen/repos","events_url":"https://api.github.com/users/wvanbergen/events{/privacy}","received_events_url":"https://api.github.com/users/wvanbergen/received_events","type":"User","site_admin":false},"body":"This is a basic implementation of the ideas we discussed before about automatically validating database constraints. \r\n\r\nFirst of all, this gem includes 3 validators:\r\n\r\n- `NotNullValidator`: checks whether the value is anything but `nil`. This is different from the standard `PresenceValidator`, because that one also errors on empty strings. `NotNullValidator` matches the NOT NULL database constraints exactly.\r\n- `BytesizeValidator`: checks whether a string/blob is not larger than a given `:maximum` in bytes. The LengthValidator will check for characters, which doesn't work for TEXT and BLOB fields.\r\n- `BasicMultilingualPlaneValidator`: checks whether all characters in a string are from the basic multilingual plane, i.e. fit in 3 UTF-8 bytes.\r\n\r\nYou can instantiate these by hand if you wish:\r\n\r\n``` ruby\r\n   validates :required, not_null: true\r\n   validates :string, basic_multilingual_plane: true\r\n   validates :blob, bytesize: { maximum: 65535 }\r\n```\r\n\r\nBut next to these validators, it also adds a `DatabaseConstraintsValidator`, which generates a bunch of sub-validators based on the schema.\r\n- For NOT NULL fields, it can add a NotNullValidator.\r\n- For textual and binary blob fields, it can add a BytesizeValidator (TEXT and BLOB fields) or a LengthValidator (VARCHAR fields).\r\n- For textual fields that have a `utf8mb3` collation, it can add a `BasicMultilingualPlaneValidator`.\r\n\r\nBy default, it will only generate size validators, unless you specify you want other validators as well.\r\n\r\n``` ruby\r\n  validates :string, database_constraints: true # adds just a size validator\r\n  # or, specify you want everything:\r\n  validates :required_string, database_constraints: { constraints: [:not_null, :size, \r\n:basic_multilingual_plane] }\r\n  # or, specify you want everything available:\r\n  validates :required_string, database_constraints: { constraints: :all }\r\n\r\n```\r\n\r\nOne thing to note is that the validators are created lazily, i.e. the first time a record is validated. This prevents leading the schema of the table at boot time.\r\n\r\n@fw42 @byroot @jduff for review.","created_at":"2014-10-13T22:08:57Z","updated_at":"2014-10-15T11:05:02Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3e506bf26c80d63fa93bb5ce53fd57b2815d1e64","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/pulls/2/commits","review_comments_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/pulls/2/comments","review_comment_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/pulls/comments/{number}","comments_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/issues/2/comments","statuses_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/statuses/c22e4f8261e065e7ca2a7776634832ce775c7f00","head":{"label":"wvanbergen:initial_implementation","ref":"initial_implementation","sha":"c22e4f8261e065e7ca2a7776634832ce775c7f00","user":{"login":"wvanbergen","id":15870,"avatar_url":"https://avatars.githubusercontent.com/u/15870?v=2","gravatar_id":"","url":"https://api.github.com/users/wvanbergen","html_url":"https://github.com/wvanbergen","followers_url":"https://api.github.com/users/wvanbergen/followers","following_url":"https://api.github.com/users/wvanbergen/following{/other_user}","gists_url":"https://api.github.com/users/wvanbergen/gists{/gist_id}","starred_url":"https://api.github.com/users/wvanbergen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wvanbergen/subscriptions","organizations_url":"https://api.github.com/users/wvanbergen/orgs","repos_url":"https://api.github.com/users/wvanbergen/repos","events_url":"https://api.github.com/users/wvanbergen/events{/privacy}","received_events_url":"https://api.github.com/users/wvanbergen/received_events","type":"User","site_admin":false},"repo":{"id":25174018,"name":"activerecord-databasevalidations","full_name":"wvanbergen/activerecord-databasevalidations","owner":{"login":"wvanbergen","id":15870,"avatar_url":"https://avatars.githubusercontent.com/u/15870?v=2","gravatar_id":"","url":"https://api.github.com/users/wvanbergen","html_url":"https://github.com/wvanbergen","followers_url":"https://api.github.com/users/wvanbergen/followers","following_url":"https://api.github.com/users/wvanbergen/following{/other_user}","gists_url":"https://api.github.com/users/wvanbergen/gists{/gist_id}","starred_url":"https://api.github.com/users/wvanbergen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wvanbergen/subscriptions","organizations_url":"https://api.github.com/users/wvanbergen/orgs","repos_url":"https://api.github.com/users/wvanbergen/repos","events_url":"https://api.github.com/users/wvanbergen/events{/privacy}","received_events_url":"https://api.github.com/users/wvanbergen/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/wvanbergen/activerecord-databasevalidations","description":"Add validations to your ActiveRecord models based on your database constraints.","fork":false,"url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations","forks_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/forks","keys_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/keys{/key_id}","collaborators_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/teams","hooks_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/hooks","issue_events_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/issues/events{/number}","events_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/events","assignees_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/assignees{/user}","branches_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/branches{/branch}","tags_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/tags","blobs_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/git/refs{/sha}","trees_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/git/trees{/sha}","statuses_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/statuses/{sha}","languages_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/languages","stargazers_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/stargazers","contributors_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/contributors","subscribers_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/subscribers","subscription_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/subscription","commits_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/commits{/sha}","git_commits_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/git/commits{/sha}","comments_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/comments{/number}","issue_comment_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/issues/comments/{number}","contents_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/contents/{+path}","compare_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/compare/{base}...{head}","merges_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/merges","archive_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/downloads","issues_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/issues{/number}","pulls_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/pulls{/number}","milestones_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/milestones{/number}","notifications_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/labels{/name}","releases_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/releases{/id}","created_at":"2014-10-13T19:27:24Z","updated_at":"2014-10-14T20:31:29Z","pushed_at":"2014-10-14T20:37:25Z","git_url":"git://github.com/wvanbergen/activerecord-databasevalidations.git","ssh_url":"git@github.com:wvanbergen/activerecord-databasevalidations.git","clone_url":"https://github.com/wvanbergen/activerecord-databasevalidations.git","svn_url":"https://github.com/wvanbergen/activerecord-databasevalidations","homepage":null,"size":0,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"wvanbergen:master","ref":"master","sha":"2b35d61a2516db991f095e77e2b022e91ac2c721","user":{"login":"wvanbergen","id":15870,"avatar_url":"https://avatars.githubusercontent.com/u/15870?v=2","gravatar_id":"","url":"https://api.github.com/users/wvanbergen","html_url":"https://github.com/wvanbergen","followers_url":"https://api.github.com/users/wvanbergen/followers","following_url":"https://api.github.com/users/wvanbergen/following{/other_user}","gists_url":"https://api.github.com/users/wvanbergen/gists{/gist_id}","starred_url":"https://api.github.com/users/wvanbergen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wvanbergen/subscriptions","organizations_url":"https://api.github.com/users/wvanbergen/orgs","repos_url":"https://api.github.com/users/wvanbergen/repos","events_url":"https://api.github.com/users/wvanbergen/events{/privacy}","received_events_url":"https://api.github.com/users/wvanbergen/received_events","type":"User","site_admin":false},"repo":{"id":25174018,"name":"activerecord-databasevalidations","full_name":"wvanbergen/activerecord-databasevalidations","owner":{"login":"wvanbergen","id":15870,"avatar_url":"https://avatars.githubusercontent.com/u/15870?v=2","gravatar_id":"","url":"https://api.github.com/users/wvanbergen","html_url":"https://github.com/wvanbergen","followers_url":"https://api.github.com/users/wvanbergen/followers","following_url":"https://api.github.com/users/wvanbergen/following{/other_user}","gists_url":"https://api.github.com/users/wvanbergen/gists{/gist_id}","starred_url":"https://api.github.com/users/wvanbergen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wvanbergen/subscriptions","organizations_url":"https://api.github.com/users/wvanbergen/orgs","repos_url":"https://api.github.com/users/wvanbergen/repos","events_url":"https://api.github.com/users/wvanbergen/events{/privacy}","received_events_url":"https://api.github.com/users/wvanbergen/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/wvanbergen/activerecord-databasevalidations","description":"Add validations to your ActiveRecord models based on your database constraints.","fork":false,"url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations","forks_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/forks","keys_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/keys{/key_id}","collaborators_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/teams","hooks_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/hooks","issue_events_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/issues/events{/number}","events_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/events","assignees_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/assignees{/user}","branches_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/branches{/branch}","tags_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/tags","blobs_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/git/refs{/sha}","trees_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/git/trees{/sha}","statuses_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/statuses/{sha}","languages_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/languages","stargazers_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/stargazers","contributors_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/contributors","subscribers_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/subscribers","subscription_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/subscription","commits_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/commits{/sha}","git_commits_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/git/commits{/sha}","comments_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/comments{/number}","issue_comment_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/issues/comments/{number}","contents_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/contents/{+path}","compare_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/compare/{base}...{head}","merges_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/merges","archive_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/downloads","issues_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/issues{/number}","pulls_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/pulls{/number}","milestones_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/milestones{/number}","notifications_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/labels{/name}","releases_url":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/releases{/id}","created_at":"2014-10-13T19:27:24Z","updated_at":"2014-10-14T20:31:29Z","pushed_at":"2014-10-14T20:37:25Z","git_url":"git://github.com/wvanbergen/activerecord-databasevalidations.git","ssh_url":"git@github.com:wvanbergen/activerecord-databasevalidations.git","clone_url":"https://github.com/wvanbergen/activerecord-databasevalidations.git","svn_url":"https://github.com/wvanbergen/activerecord-databasevalidations","homepage":null,"size":0,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/pulls/2"},"html":{"href":"https://github.com/wvanbergen/activerecord-databasevalidations/pull/2"},"issue":{"href":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/issues/2"},"comments":{"href":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/issues/2/comments"},"review_comments":{"href":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/pulls/2/comments"},"review_comment":{"href":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/pulls/2/commits"},"statuses":{"href":"https://api.github.com/repos/wvanbergen/activerecord-databasevalidations/statuses/c22e4f8261e065e7ca2a7776634832ce775c7f00"}}}}