{"action":"created","comment":{"url":"https://api.github.com/repos/sgrif/diesel/pulls/comments/52688021","id":52688021,"diff_hunk":"@@ -114,6 +114,30 @@ impl Connection for PgConnection {\n     fn get_transaction_depth(&self) -> i32 {\n         self.transaction_depth.get()\n     }\n+\n+    fn setup_helper_functions(&self) {\n+        self.execute(\n+            \"CREATE OR REPLACE FUNCTION diesel_set_updated_at() RETURNS trigger AS $$\n+            BEGIN\n+                IF (\n+                    NEW IS DISTINCT FROM OLD AND\n+                    NEW.updated_at IS NOT DISTINCT FROM OLD.updated_at\n+                ) THEN\n+                    NEW.updated_at := current_timestamp;\n+                END IF;\n+                RETURN NEW;\n+            END;\n+            $$ LANGUAGE plpgsql;\"\n+        ).expect(\"Error creating function `diesel_set_updated_at()`\");\n+        self.execute(\n+            \"CREATE OR REPLACE FUNCTION diesel_manage_updated_at(_tbl regclass) RETURNS VOID AS $$\n+            BEGIN\n+                EXECUTE format('CREATE TRIGGER set_updated_at BEFORE UPDATE ON %s\n+                FOR EACH ROW EXECUTE PROCEDURE diesel_set_updated_at()', _tbl);\n+            END;\n+            $$ LANGUAGE plpgsql;\"","path":"diesel/src/pg/connection/mod.rs","position":null,"original_position":25,"commit_id":"bdce9c47493ba9df2a36d4e3c8182ef4c73aabab","original_commit_id":"20c14a1b4c6304b5d82c3d0a62843b3e61234a79","user":{"login":"robertmaloney","id":7446202,"avatar_url":"https://avatars.githubusercontent.com/u/7446202?v=3","gravatar_id":"","url":"https://api.github.com/users/robertmaloney","html_url":"https://github.com/robertmaloney","followers_url":"https://api.github.com/users/robertmaloney/followers","following_url":"https://api.github.com/users/robertmaloney/following{/other_user}","gists_url":"https://api.github.com/users/robertmaloney/gists{/gist_id}","starred_url":"https://api.github.com/users/robertmaloney/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robertmaloney/subscriptions","organizations_url":"https://api.github.com/users/robertmaloney/orgs","repos_url":"https://api.github.com/users/robertmaloney/repos","events_url":"https://api.github.com/users/robertmaloney/events{/privacy}","received_events_url":"https://api.github.com/users/robertmaloney/received_events","type":"User","site_admin":false},"body":"Done. I put the sql in a `setup` folder.","created_at":"2016-02-11T23:58:01Z","updated_at":"2016-02-11T23:58:01Z","html_url":"https://github.com/sgrif/diesel/pull/178#discussion_r52688021","pull_request_url":"https://api.github.com/repos/sgrif/diesel/pulls/178","_links":{"self":{"href":"https://api.github.com/repos/sgrif/diesel/pulls/comments/52688021"},"html":{"href":"https://github.com/sgrif/diesel/pull/178#discussion_r52688021"},"pull_request":{"href":"https://api.github.com/repos/sgrif/diesel/pulls/178"}}},"pull_request":{"url":"https://api.github.com/repos/sgrif/diesel/pulls/178","id":58066418,"html_url":"https://github.com/sgrif/diesel/pull/178","diff_url":"https://github.com/sgrif/diesel/pull/178.diff","patch_url":"https://github.com/sgrif/diesel/pull/178.patch","issue_url":"https://api.github.com/repos/sgrif/diesel/issues/178","number":178,"state":"open","locked":false,"title":"Add helpers for managing `updated_at TIMESTAMP` columns","user":{"login":"robertmaloney","id":7446202,"avatar_url":"https://avatars.githubusercontent.com/u/7446202?v=3","gravatar_id":"","url":"https://api.github.com/users/robertmaloney","html_url":"https://github.com/robertmaloney","followers_url":"https://api.github.com/users/robertmaloney/followers","following_url":"https://api.github.com/users/robertmaloney/following{/other_user}","gists_url":"https://api.github.com/users/robertmaloney/gists{/gist_id}","starred_url":"https://api.github.com/users/robertmaloney/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robertmaloney/subscriptions","organizations_url":"https://api.github.com/users/robertmaloney/orgs","repos_url":"https://api.github.com/users/robertmaloney/repos","events_url":"https://api.github.com/users/robertmaloney/events{/privacy}","received_events_url":"https://api.github.com/users/robertmaloney/received_events","type":"User","site_admin":false},"body":"Fixes #91 \r\n\r\nI also added some validation in the setup method to ensure that they are applying the trigger to a valid table, for a bit better user experience.\r\n\r\n###### TODO\r\n* [x] Migrate functions setup around `__diesel_schema_migrations` setup\r\n* [x] Remove CLI","created_at":"2016-02-02T23:15:07Z","updated_at":"2016-02-11T23:58:01Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4c3a533e6a984ac18e0d2252dd9421762ff5919b","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/sgrif/diesel/pulls/178/commits","review_comments_url":"https://api.github.com/repos/sgrif/diesel/pulls/178/comments","review_comment_url":"https://api.github.com/repos/sgrif/diesel/pulls/comments{/number}","comments_url":"https://api.github.com/repos/sgrif/diesel/issues/178/comments","statuses_url":"https://api.github.com/repos/sgrif/diesel/statuses/bdce9c47493ba9df2a36d4e3c8182ef4c73aabab","head":{"label":"robertmaloney:rm/timestamp-helpers","ref":"rm/timestamp-helpers","sha":"bdce9c47493ba9df2a36d4e3c8182ef4c73aabab","user":{"login":"robertmaloney","id":7446202,"avatar_url":"https://avatars.githubusercontent.com/u/7446202?v=3","gravatar_id":"","url":"https://api.github.com/users/robertmaloney","html_url":"https://github.com/robertmaloney","followers_url":"https://api.github.com/users/robertmaloney/followers","following_url":"https://api.github.com/users/robertmaloney/following{/other_user}","gists_url":"https://api.github.com/users/robertmaloney/gists{/gist_id}","starred_url":"https://api.github.com/users/robertmaloney/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robertmaloney/subscriptions","organizations_url":"https://api.github.com/users/robertmaloney/orgs","repos_url":"https://api.github.com/users/robertmaloney/repos","events_url":"https://api.github.com/users/robertmaloney/events{/privacy}","received_events_url":"https://api.github.com/users/robertmaloney/received_events","type":"User","site_admin":false},"repo":{"id":50739751,"name":"diesel","full_name":"robertmaloney/diesel","owner":{"login":"robertmaloney","id":7446202,"avatar_url":"https://avatars.githubusercontent.com/u/7446202?v=3","gravatar_id":"","url":"https://api.github.com/users/robertmaloney","html_url":"https://github.com/robertmaloney","followers_url":"https://api.github.com/users/robertmaloney/followers","following_url":"https://api.github.com/users/robertmaloney/following{/other_user}","gists_url":"https://api.github.com/users/robertmaloney/gists{/gist_id}","starred_url":"https://api.github.com/users/robertmaloney/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robertmaloney/subscriptions","organizations_url":"https://api.github.com/users/robertmaloney/orgs","repos_url":"https://api.github.com/users/robertmaloney/repos","events_url":"https://api.github.com/users/robertmaloney/events{/privacy}","received_events_url":"https://api.github.com/users/robertmaloney/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/robertmaloney/diesel","description":"A safe, extensible ORM and Query Builder for Rust","fork":true,"url":"https://api.github.com/repos/robertmaloney/diesel","forks_url":"https://api.github.com/repos/robertmaloney/diesel/forks","keys_url":"https://api.github.com/repos/robertmaloney/diesel/keys{/key_id}","collaborators_url":"https://api.github.com/repos/robertmaloney/diesel/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/robertmaloney/diesel/teams","hooks_url":"https://api.github.com/repos/robertmaloney/diesel/hooks","issue_events_url":"https://api.github.com/repos/robertmaloney/diesel/issues/events{/number}","events_url":"https://api.github.com/repos/robertmaloney/diesel/events","assignees_url":"https://api.github.com/repos/robertmaloney/diesel/assignees{/user}","branches_url":"https://api.github.com/repos/robertmaloney/diesel/branches{/branch}","tags_url":"https://api.github.com/repos/robertmaloney/diesel/tags","blobs_url":"https://api.github.com/repos/robertmaloney/diesel/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/robertmaloney/diesel/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/robertmaloney/diesel/git/refs{/sha}","trees_url":"https://api.github.com/repos/robertmaloney/diesel/git/trees{/sha}","statuses_url":"https://api.github.com/repos/robertmaloney/diesel/statuses/{sha}","languages_url":"https://api.github.com/repos/robertmaloney/diesel/languages","stargazers_url":"https://api.github.com/repos/robertmaloney/diesel/stargazers","contributors_url":"https://api.github.com/repos/robertmaloney/diesel/contributors","subscribers_url":"https://api.github.com/repos/robertmaloney/diesel/subscribers","subscription_url":"https://api.github.com/repos/robertmaloney/diesel/subscription","commits_url":"https://api.github.com/repos/robertmaloney/diesel/commits{/sha}","git_commits_url":"https://api.github.com/repos/robertmaloney/diesel/git/commits{/sha}","comments_url":"https://api.github.com/repos/robertmaloney/diesel/comments{/number}","issue_comment_url":"https://api.github.com/repos/robertmaloney/diesel/issues/comments{/number}","contents_url":"https://api.github.com/repos/robertmaloney/diesel/contents/{+path}","compare_url":"https://api.github.com/repos/robertmaloney/diesel/compare/{base}...{head}","merges_url":"https://api.github.com/repos/robertmaloney/diesel/merges","archive_url":"https://api.github.com/repos/robertmaloney/diesel/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/robertmaloney/diesel/downloads","issues_url":"https://api.github.com/repos/robertmaloney/diesel/issues{/number}","pulls_url":"https://api.github.com/repos/robertmaloney/diesel/pulls{/number}","milestones_url":"https://api.github.com/repos/robertmaloney/diesel/milestones{/number}","notifications_url":"https://api.github.com/repos/robertmaloney/diesel/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/robertmaloney/diesel/labels{/name}","releases_url":"https://api.github.com/repos/robertmaloney/diesel/releases{/id}","deployments_url":"https://api.github.com/repos/robertmaloney/diesel/deployments","created_at":"2016-01-30T18:59:45Z","updated_at":"2016-01-30T18:59:47Z","pushed_at":"2016-02-11T23:36:16Z","git_url":"git://github.com/robertmaloney/diesel.git","ssh_url":"git@github.com:robertmaloney/diesel.git","clone_url":"https://github.com/robertmaloney/diesel.git","svn_url":"https://github.com/robertmaloney/diesel","homepage":"","size":3176,"stargazers_count":0,"watchers_count":0,"language":"Rust","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":"sgrif:master","ref":"master","sha":"2d05632dfe49931de0b2bcdea98237a97b91a2cf","user":{"login":"sgrif","id":1529387,"avatar_url":"https://avatars.githubusercontent.com/u/1529387?v=3","gravatar_id":"","url":"https://api.github.com/users/sgrif","html_url":"https://github.com/sgrif","followers_url":"https://api.github.com/users/sgrif/followers","following_url":"https://api.github.com/users/sgrif/following{/other_user}","gists_url":"https://api.github.com/users/sgrif/gists{/gist_id}","starred_url":"https://api.github.com/users/sgrif/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sgrif/subscriptions","organizations_url":"https://api.github.com/users/sgrif/orgs","repos_url":"https://api.github.com/users/sgrif/repos","events_url":"https://api.github.com/users/sgrif/events{/privacy}","received_events_url":"https://api.github.com/users/sgrif/received_events","type":"User","site_admin":false},"repo":{"id":41609775,"name":"diesel","full_name":"sgrif/diesel","owner":{"login":"sgrif","id":1529387,"avatar_url":"https://avatars.githubusercontent.com/u/1529387?v=3","gravatar_id":"","url":"https://api.github.com/users/sgrif","html_url":"https://github.com/sgrif","followers_url":"https://api.github.com/users/sgrif/followers","following_url":"https://api.github.com/users/sgrif/following{/other_user}","gists_url":"https://api.github.com/users/sgrif/gists{/gist_id}","starred_url":"https://api.github.com/users/sgrif/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sgrif/subscriptions","organizations_url":"https://api.github.com/users/sgrif/orgs","repos_url":"https://api.github.com/users/sgrif/repos","events_url":"https://api.github.com/users/sgrif/events{/privacy}","received_events_url":"https://api.github.com/users/sgrif/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/sgrif/diesel","description":"A safe, extensible ORM and Query Builder for Rust","fork":false,"url":"https://api.github.com/repos/sgrif/diesel","forks_url":"https://api.github.com/repos/sgrif/diesel/forks","keys_url":"https://api.github.com/repos/sgrif/diesel/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sgrif/diesel/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sgrif/diesel/teams","hooks_url":"https://api.github.com/repos/sgrif/diesel/hooks","issue_events_url":"https://api.github.com/repos/sgrif/diesel/issues/events{/number}","events_url":"https://api.github.com/repos/sgrif/diesel/events","assignees_url":"https://api.github.com/repos/sgrif/diesel/assignees{/user}","branches_url":"https://api.github.com/repos/sgrif/diesel/branches{/branch}","tags_url":"https://api.github.com/repos/sgrif/diesel/tags","blobs_url":"https://api.github.com/repos/sgrif/diesel/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sgrif/diesel/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sgrif/diesel/git/refs{/sha}","trees_url":"https://api.github.com/repos/sgrif/diesel/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sgrif/diesel/statuses/{sha}","languages_url":"https://api.github.com/repos/sgrif/diesel/languages","stargazers_url":"https://api.github.com/repos/sgrif/diesel/stargazers","contributors_url":"https://api.github.com/repos/sgrif/diesel/contributors","subscribers_url":"https://api.github.com/repos/sgrif/diesel/subscribers","subscription_url":"https://api.github.com/repos/sgrif/diesel/subscription","commits_url":"https://api.github.com/repos/sgrif/diesel/commits{/sha}","git_commits_url":"https://api.github.com/repos/sgrif/diesel/git/commits{/sha}","comments_url":"https://api.github.com/repos/sgrif/diesel/comments{/number}","issue_comment_url":"https://api.github.com/repos/sgrif/diesel/issues/comments{/number}","contents_url":"https://api.github.com/repos/sgrif/diesel/contents/{+path}","compare_url":"https://api.github.com/repos/sgrif/diesel/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sgrif/diesel/merges","archive_url":"https://api.github.com/repos/sgrif/diesel/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sgrif/diesel/downloads","issues_url":"https://api.github.com/repos/sgrif/diesel/issues{/number}","pulls_url":"https://api.github.com/repos/sgrif/diesel/pulls{/number}","milestones_url":"https://api.github.com/repos/sgrif/diesel/milestones{/number}","notifications_url":"https://api.github.com/repos/sgrif/diesel/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sgrif/diesel/labels{/name}","releases_url":"https://api.github.com/repos/sgrif/diesel/releases{/id}","deployments_url":"https://api.github.com/repos/sgrif/diesel/deployments","created_at":"2015-08-29T22:51:00Z","updated_at":"2016-02-11T16:49:51Z","pushed_at":"2016-02-11T23:36:16Z","git_url":"git://github.com/sgrif/diesel.git","ssh_url":"git@github.com:sgrif/diesel.git","clone_url":"https://github.com/sgrif/diesel.git","svn_url":"https://github.com/sgrif/diesel","homepage":"","size":3672,"stargazers_count":708,"watchers_count":708,"language":"Rust","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":41,"mirror_url":null,"open_issues_count":33,"forks":41,"open_issues":33,"watchers":708,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/sgrif/diesel/pulls/178"},"html":{"href":"https://github.com/sgrif/diesel/pull/178"},"issue":{"href":"https://api.github.com/repos/sgrif/diesel/issues/178"},"comments":{"href":"https://api.github.com/repos/sgrif/diesel/issues/178/comments"},"review_comments":{"href":"https://api.github.com/repos/sgrif/diesel/pulls/178/comments"},"review_comment":{"href":"https://api.github.com/repos/sgrif/diesel/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/sgrif/diesel/pulls/178/commits"},"statuses":{"href":"https://api.github.com/repos/sgrif/diesel/statuses/bdce9c47493ba9df2a36d4e3c8182ef4c73aabab"}}}}