{"action":"created","comment":{"url":"https://api.github.com/repos/habitat-sh/habitat/pulls/comments/125928768","pull_request_review_id":48337969,"id":125928768,"diff_hunk":"@@ -42,44 +42,94 @@ pub fn migrate(migrator: &mut Migrator) -> Result<()> {\n              )\"#,\n     )?;\n     migrator.migrate(\"originsrv\",\n-                 r#\"CREATE OR REPLACE FUNCTION insert_origin_package_v1 (\n-                    op_origin_id bigint,\n-                    op_owner_id bigint,\n-                    op_name text,\n-                    op_ident text,\n-                    op_checksum text,\n-                    op_manifest text,\n-                    op_config text,\n-                    op_target text,\n-                    op_deps text,\n-                    op_tdeps text,\n-                    op_exposes text\n-                 ) RETURNS SETOF origin_packages AS $$\n-                     DECLARE\n-                        inserted_package origin_packages;\n-                        channel_id bigint;\n-                     BEGIN\n-                         INSERT INTO origin_packages (origin_id, owner_id, name, ident, checksum, manifest, config, target, deps, tdeps, exposes)\n-                                VALUES (op_origin_id, op_owner_id, op_name, op_ident, op_checksum, op_manifest, op_config, op_target, op_deps, op_tdeps, op_exposes)\n-                                RETURNING * into inserted_package;\n+                 r#\"CREATE OR REPLACE FUNCTION insert_origin_package_v2 (\n+                        op_origin_id bigint,\n+                        op_owner_id bigint,\n+                        op_name text,\n+                        op_ident text,\n+                        op_checksum text,\n+                        op_manifest text,\n+                        op_config text,\n+                        op_target text,\n+                        op_deps text,\n+                        op_tdeps text,\n+                        op_exposes text\n+                    ) RETURNS TABLE (\n+                        id bigint,\n+                        name text,\n+                        origin_id bigint,\n+                        owner_id bigint,\n+                        ident text,\n+                        checksum text,\n+                        manifest text,\n+                        config text,\n+                        target text,\n+                        deps text,\n+                        tdeps text,\n+                        exposes text,\n+                        channels text[]\n+                    ) AS $$\n+                        DECLARE\n+                            channel_id bigint;\n+                            package_id bigint;\n+                        BEGIN\n+                            INSERT INTO origin_packages (origin_id, owner_id, name, ident, checksum, manifest, config, target, deps, tdeps, exposes)\n+                            VALUES (op_origin_id, op_owner_id, op_name, op_ident, op_checksum, op_manifest, op_config, op_target, op_deps, op_tdeps, op_exposes)\n+                            RETURNING origin_packages.id INTO package_id;\n+\n+                            SELECT oc.id FROM origin_channels oc WHERE oc.origin_id = op_origin_id AND oc.name = 'unstable'\n+                              INTO channel_id;\n \n-                         SELECT id FROM origin_channels WHERE origin_id = op_origin_id AND name = 'unstable' INTO channel_id;\n-                         PERFORM promote_origin_package_v1(channel_id, inserted_package.id);\n+                            PERFORM promote_origin_package_v1(channel_id, package_id);\n \n-                         RETURN NEXT inserted_package;\n-                         RETURN;\n-                     END\n-                 $$ LANGUAGE plpgsql VOLATILE\"#)?;\n+                            RETURN QUERY\n+                                SELECT p.id, p.name, p.origin_id, p.owner_id, p.ident, p.checksum, p.manifest,\n+                                       p.config, p.target, p.deps, p.tdeps, p.exposes,\n+                                    (SELECT ARRAY(SELECT c.name\n+                                                    FROM origin_channels c\n+                                                   WHERE c.id IN (SELECT cp.channel_id\n+                                                                    FROM origin_channel_packages cp\n+                                                                   WHERE cp.package_id = p.id\n+                                                                ORDER BY cp.created_at DESC))) AS channels\n+                                  FROM origin_packages p\n+                                 WHERE p.id = package_id;\n+                            RETURN;","path":"components/builder-originsrv/src/migrations/origin_packages.rs","position":81,"original_position":81,"commit_id":"098e2b44254ab92d8588ffe1a99e2a25c93d2dec","original_commit_id":"098e2b44254ab92d8588ffe1a99e2a25c93d2dec","user":{"login":"christophermaier","id":207178,"avatar_url":"https://avatars1.githubusercontent.com/u/207178?v=3","gravatar_id":"","url":"https://api.github.com/users/christophermaier","html_url":"https://github.com/christophermaier","followers_url":"https://api.github.com/users/christophermaier/followers","following_url":"https://api.github.com/users/christophermaier/following{/other_user}","gists_url":"https://api.github.com/users/christophermaier/gists{/gist_id}","starred_url":"https://api.github.com/users/christophermaier/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/christophermaier/subscriptions","organizations_url":"https://api.github.com/users/christophermaier/orgs","repos_url":"https://api.github.com/users/christophermaier/repos","events_url":"https://api.github.com/users/christophermaier/events{/privacy}","received_events_url":"https://api.github.com/users/christophermaier/received_events","type":"User","site_admin":false},"body":"Yeah, this looks like it's performing essentially the same query as the earlier function, but without the channel restriction. This really makes me favor a view for this logic now; it encapsulates all the join logic, but you can modify the selection criteria when you call it. As a bonus, you can also refer to the view as a return type, so you don't need to painstakingly list all the columns each time. With a concrete type, I think you can also indicate that you're only going to be returning a single row instead of a table (that you have to remember only ever has at most one row), but that's not 100% necessary.","created_at":"2017-07-06T15:10:44Z","updated_at":"2017-07-06T15:36:49Z","html_url":"https://github.com/habitat-sh/habitat/pull/2690#discussion_r125928768","pull_request_url":"https://api.github.com/repos/habitat-sh/habitat/pulls/2690","_links":{"self":{"href":"https://api.github.com/repos/habitat-sh/habitat/pulls/comments/125928768"},"html":{"href":"https://github.com/habitat-sh/habitat/pull/2690#discussion_r125928768"},"pull_request":{"href":"https://api.github.com/repos/habitat-sh/habitat/pulls/2690"}}},"pull_request":{"url":"https://api.github.com/repos/habitat-sh/habitat/pulls/2690","id":129080630,"html_url":"https://github.com/habitat-sh/habitat/pull/2690","diff_url":"https://github.com/habitat-sh/habitat/pull/2690.diff","patch_url":"https://github.com/habitat-sh/habitat/pull/2690.patch","issue_url":"https://api.github.com/repos/habitat-sh/habitat/issues/2690","number":2690,"state":"open","locked":false,"title":"Indicate package channels in the depot UI","user":{"login":"cnunciato","id":274700,"avatar_url":"https://avatars0.githubusercontent.com/u/274700?v=3","gravatar_id":"","url":"https://api.github.com/users/cnunciato","html_url":"https://github.com/cnunciato","followers_url":"https://api.github.com/users/cnunciato/followers","following_url":"https://api.github.com/users/cnunciato/following{/other_user}","gists_url":"https://api.github.com/users/cnunciato/gists{/gist_id}","starred_url":"https://api.github.com/users/cnunciato/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cnunciato/subscriptions","organizations_url":"https://api.github.com/users/cnunciato/orgs","repos_url":"https://api.github.com/users/cnunciato/repos","events_url":"https://api.github.com/users/cnunciato/events{/privacy}","received_events_url":"https://api.github.com/users/cnunciato/received_events","type":"User","site_admin":false},"body":"This change adds a `channels` property to the depot API and renders a given package's list of channels in the depot UI.\r\n\r\nSee the API documentation for details. Affected API endpoints are:\r\n\r\n```\r\n/pkgs/:origin/:name/latest\r\n/pkgs/:origin/:name/:version\r\n/pkgs/:origin/:name/:version/latest\r\n/pkgs/:origin/:name/:version/:release\r\n```\r\n\r\n![](https://media.tenor.com/images/22b001cbeb37bab3a9511d37bced53bd/tenor.gif)\r\n\r\nSigned-off-by: Christian Nunciato <cnunciato@chef.io>","created_at":"2017-07-06T00:18:57Z","updated_at":"2017-07-06T15:36:49Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3cd036d94b58dabdbea52d720be18b5604e2f93a","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/habitat-sh/habitat/pulls/2690/commits","review_comments_url":"https://api.github.com/repos/habitat-sh/habitat/pulls/2690/comments","review_comment_url":"https://api.github.com/repos/habitat-sh/habitat/pulls/comments{/number}","comments_url":"https://api.github.com/repos/habitat-sh/habitat/issues/2690/comments","statuses_url":"https://api.github.com/repos/habitat-sh/habitat/statuses/098e2b44254ab92d8588ffe1a99e2a25c93d2dec","head":{"label":"habitat-sh:cdn/channels","ref":"cdn/channels","sha":"098e2b44254ab92d8588ffe1a99e2a25c93d2dec","user":{"login":"habitat-sh","id":18171698,"avatar_url":"https://avatars3.githubusercontent.com/u/18171698?v=3","gravatar_id":"","url":"https://api.github.com/users/habitat-sh","html_url":"https://github.com/habitat-sh","followers_url":"https://api.github.com/users/habitat-sh/followers","following_url":"https://api.github.com/users/habitat-sh/following{/other_user}","gists_url":"https://api.github.com/users/habitat-sh/gists{/gist_id}","starred_url":"https://api.github.com/users/habitat-sh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/habitat-sh/subscriptions","organizations_url":"https://api.github.com/users/habitat-sh/orgs","repos_url":"https://api.github.com/users/habitat-sh/repos","events_url":"https://api.github.com/users/habitat-sh/events{/privacy}","received_events_url":"https://api.github.com/users/habitat-sh/received_events","type":"Organization","site_admin":false},"repo":{"id":36098429,"name":"habitat","full_name":"habitat-sh/habitat","owner":{"login":"habitat-sh","id":18171698,"avatar_url":"https://avatars3.githubusercontent.com/u/18171698?v=3","gravatar_id":"","url":"https://api.github.com/users/habitat-sh","html_url":"https://github.com/habitat-sh","followers_url":"https://api.github.com/users/habitat-sh/followers","following_url":"https://api.github.com/users/habitat-sh/following{/other_user}","gists_url":"https://api.github.com/users/habitat-sh/gists{/gist_id}","starred_url":"https://api.github.com/users/habitat-sh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/habitat-sh/subscriptions","organizations_url":"https://api.github.com/users/habitat-sh/orgs","repos_url":"https://api.github.com/users/habitat-sh/repos","events_url":"https://api.github.com/users/habitat-sh/events{/privacy}","received_events_url":"https://api.github.com/users/habitat-sh/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/habitat-sh/habitat","description":"Modern applications with built-in automation","fork":false,"url":"https://api.github.com/repos/habitat-sh/habitat","forks_url":"https://api.github.com/repos/habitat-sh/habitat/forks","keys_url":"https://api.github.com/repos/habitat-sh/habitat/keys{/key_id}","collaborators_url":"https://api.github.com/repos/habitat-sh/habitat/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/habitat-sh/habitat/teams","hooks_url":"https://api.github.com/repos/habitat-sh/habitat/hooks","issue_events_url":"https://api.github.com/repos/habitat-sh/habitat/issues/events{/number}","events_url":"https://api.github.com/repos/habitat-sh/habitat/events","assignees_url":"https://api.github.com/repos/habitat-sh/habitat/assignees{/user}","branches_url":"https://api.github.com/repos/habitat-sh/habitat/branches{/branch}","tags_url":"https://api.github.com/repos/habitat-sh/habitat/tags","blobs_url":"https://api.github.com/repos/habitat-sh/habitat/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/habitat-sh/habitat/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/habitat-sh/habitat/git/refs{/sha}","trees_url":"https://api.github.com/repos/habitat-sh/habitat/git/trees{/sha}","statuses_url":"https://api.github.com/repos/habitat-sh/habitat/statuses/{sha}","languages_url":"https://api.github.com/repos/habitat-sh/habitat/languages","stargazers_url":"https://api.github.com/repos/habitat-sh/habitat/stargazers","contributors_url":"https://api.github.com/repos/habitat-sh/habitat/contributors","subscribers_url":"https://api.github.com/repos/habitat-sh/habitat/subscribers","subscription_url":"https://api.github.com/repos/habitat-sh/habitat/subscription","commits_url":"https://api.github.com/repos/habitat-sh/habitat/commits{/sha}","git_commits_url":"https://api.github.com/repos/habitat-sh/habitat/git/commits{/sha}","comments_url":"https://api.github.com/repos/habitat-sh/habitat/comments{/number}","issue_comment_url":"https://api.github.com/repos/habitat-sh/habitat/issues/comments{/number}","contents_url":"https://api.github.com/repos/habitat-sh/habitat/contents/{+path}","compare_url":"https://api.github.com/repos/habitat-sh/habitat/compare/{base}...{head}","merges_url":"https://api.github.com/repos/habitat-sh/habitat/merges","archive_url":"https://api.github.com/repos/habitat-sh/habitat/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/habitat-sh/habitat/downloads","issues_url":"https://api.github.com/repos/habitat-sh/habitat/issues{/number}","pulls_url":"https://api.github.com/repos/habitat-sh/habitat/pulls{/number}","milestones_url":"https://api.github.com/repos/habitat-sh/habitat/milestones{/number}","notifications_url":"https://api.github.com/repos/habitat-sh/habitat/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/habitat-sh/habitat/labels{/name}","releases_url":"https://api.github.com/repos/habitat-sh/habitat/releases{/id}","deployments_url":"https://api.github.com/repos/habitat-sh/habitat/deployments","created_at":"2015-05-22T22:47:14Z","updated_at":"2017-07-06T14:53:07Z","pushed_at":"2017-07-06T15:33:34Z","git_url":"git://github.com/habitat-sh/habitat.git","ssh_url":"git@github.com:habitat-sh/habitat.git","clone_url":"https://github.com/habitat-sh/habitat.git","svn_url":"https://github.com/habitat-sh/habitat","homepage":"https://www.habitat.sh","size":51954,"stargazers_count":1117,"watchers_count":1117,"language":"Rust","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":167,"mirror_url":null,"open_issues_count":239,"forks":167,"open_issues":239,"watchers":1117,"default_branch":"master"}},"base":{"label":"habitat-sh:master","ref":"master","sha":"5954d2a3ced3cd78d9d24c7080c0f256b6a7cc8d","user":{"login":"habitat-sh","id":18171698,"avatar_url":"https://avatars3.githubusercontent.com/u/18171698?v=3","gravatar_id":"","url":"https://api.github.com/users/habitat-sh","html_url":"https://github.com/habitat-sh","followers_url":"https://api.github.com/users/habitat-sh/followers","following_url":"https://api.github.com/users/habitat-sh/following{/other_user}","gists_url":"https://api.github.com/users/habitat-sh/gists{/gist_id}","starred_url":"https://api.github.com/users/habitat-sh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/habitat-sh/subscriptions","organizations_url":"https://api.github.com/users/habitat-sh/orgs","repos_url":"https://api.github.com/users/habitat-sh/repos","events_url":"https://api.github.com/users/habitat-sh/events{/privacy}","received_events_url":"https://api.github.com/users/habitat-sh/received_events","type":"Organization","site_admin":false},"repo":{"id":36098429,"name":"habitat","full_name":"habitat-sh/habitat","owner":{"login":"habitat-sh","id":18171698,"avatar_url":"https://avatars3.githubusercontent.com/u/18171698?v=3","gravatar_id":"","url":"https://api.github.com/users/habitat-sh","html_url":"https://github.com/habitat-sh","followers_url":"https://api.github.com/users/habitat-sh/followers","following_url":"https://api.github.com/users/habitat-sh/following{/other_user}","gists_url":"https://api.github.com/users/habitat-sh/gists{/gist_id}","starred_url":"https://api.github.com/users/habitat-sh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/habitat-sh/subscriptions","organizations_url":"https://api.github.com/users/habitat-sh/orgs","repos_url":"https://api.github.com/users/habitat-sh/repos","events_url":"https://api.github.com/users/habitat-sh/events{/privacy}","received_events_url":"https://api.github.com/users/habitat-sh/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/habitat-sh/habitat","description":"Modern applications with built-in automation","fork":false,"url":"https://api.github.com/repos/habitat-sh/habitat","forks_url":"https://api.github.com/repos/habitat-sh/habitat/forks","keys_url":"https://api.github.com/repos/habitat-sh/habitat/keys{/key_id}","collaborators_url":"https://api.github.com/repos/habitat-sh/habitat/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/habitat-sh/habitat/teams","hooks_url":"https://api.github.com/repos/habitat-sh/habitat/hooks","issue_events_url":"https://api.github.com/repos/habitat-sh/habitat/issues/events{/number}","events_url":"https://api.github.com/repos/habitat-sh/habitat/events","assignees_url":"https://api.github.com/repos/habitat-sh/habitat/assignees{/user}","branches_url":"https://api.github.com/repos/habitat-sh/habitat/branches{/branch}","tags_url":"https://api.github.com/repos/habitat-sh/habitat/tags","blobs_url":"https://api.github.com/repos/habitat-sh/habitat/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/habitat-sh/habitat/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/habitat-sh/habitat/git/refs{/sha}","trees_url":"https://api.github.com/repos/habitat-sh/habitat/git/trees{/sha}","statuses_url":"https://api.github.com/repos/habitat-sh/habitat/statuses/{sha}","languages_url":"https://api.github.com/repos/habitat-sh/habitat/languages","stargazers_url":"https://api.github.com/repos/habitat-sh/habitat/stargazers","contributors_url":"https://api.github.com/repos/habitat-sh/habitat/contributors","subscribers_url":"https://api.github.com/repos/habitat-sh/habitat/subscribers","subscription_url":"https://api.github.com/repos/habitat-sh/habitat/subscription","commits_url":"https://api.github.com/repos/habitat-sh/habitat/commits{/sha}","git_commits_url":"https://api.github.com/repos/habitat-sh/habitat/git/commits{/sha}","comments_url":"https://api.github.com/repos/habitat-sh/habitat/comments{/number}","issue_comment_url":"https://api.github.com/repos/habitat-sh/habitat/issues/comments{/number}","contents_url":"https://api.github.com/repos/habitat-sh/habitat/contents/{+path}","compare_url":"https://api.github.com/repos/habitat-sh/habitat/compare/{base}...{head}","merges_url":"https://api.github.com/repos/habitat-sh/habitat/merges","archive_url":"https://api.github.com/repos/habitat-sh/habitat/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/habitat-sh/habitat/downloads","issues_url":"https://api.github.com/repos/habitat-sh/habitat/issues{/number}","pulls_url":"https://api.github.com/repos/habitat-sh/habitat/pulls{/number}","milestones_url":"https://api.github.com/repos/habitat-sh/habitat/milestones{/number}","notifications_url":"https://api.github.com/repos/habitat-sh/habitat/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/habitat-sh/habitat/labels{/name}","releases_url":"https://api.github.com/repos/habitat-sh/habitat/releases{/id}","deployments_url":"https://api.github.com/repos/habitat-sh/habitat/deployments","created_at":"2015-05-22T22:47:14Z","updated_at":"2017-07-06T14:53:07Z","pushed_at":"2017-07-06T15:33:34Z","git_url":"git://github.com/habitat-sh/habitat.git","ssh_url":"git@github.com:habitat-sh/habitat.git","clone_url":"https://github.com/habitat-sh/habitat.git","svn_url":"https://github.com/habitat-sh/habitat","homepage":"https://www.habitat.sh","size":51954,"stargazers_count":1117,"watchers_count":1117,"language":"Rust","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":167,"mirror_url":null,"open_issues_count":239,"forks":167,"open_issues":239,"watchers":1117,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/habitat-sh/habitat/pulls/2690"},"html":{"href":"https://github.com/habitat-sh/habitat/pull/2690"},"issue":{"href":"https://api.github.com/repos/habitat-sh/habitat/issues/2690"},"comments":{"href":"https://api.github.com/repos/habitat-sh/habitat/issues/2690/comments"},"review_comments":{"href":"https://api.github.com/repos/habitat-sh/habitat/pulls/2690/comments"},"review_comment":{"href":"https://api.github.com/repos/habitat-sh/habitat/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/habitat-sh/habitat/pulls/2690/commits"},"statuses":{"href":"https://api.github.com/repos/habitat-sh/habitat/statuses/098e2b44254ab92d8588ffe1a99e2a25c93d2dec"}}}}
{"actor":{"display_login":"christophermaier"}}