{"action":"created","comment":{"url":"https://api.github.com/repos/heroku/heroku-fork/pulls/comments/51078406","id":51078406,"diff_hunk":"@@ -7,46 +9,50 @@ function Addons (heroku, postgres) {\n }\n \n Addons.prototype = {\n-  addAddon: function* (app, addon) {\n+  addAddon: function* (app, addon, attachment) {\n     try {\n-      process.stdout.write(`Adding addon ${addon.plan.name} to ${app.name}... `);\n-      addon = yield this.heroku.apps(app.name).addons().create({plan: addon.plan.name});\n+      process.stdout.write(`Adding addon ${cli.color.magenta(addon.plan.name)} to ${cli.color.cyan(app.name)} as ${cli.color.green(attachment.name)}... `);\n+      addon = yield this.heroku.apps(app.name).addons().create({attachment: {name: attachment.name}, plan: addon.plan.name});\n       console.log('done');\n       return addon;\n     } catch (err) {\n-      console.error(`Skipped addon ${addon.plan.name}`);\n-      if (err.body) {\n-        console.error(` !    ${err.body.message}`);\n-      } else {\n-        console.error(err);\n-      }\n+      console.error(`Skipped addon ${cli.color.magenta(addon.plan.name)}`);\n+      if (err.body) cli.error(err.body.message);\n+      else          cli.error(err);\n     }\n   },\n \n-  getAddons: function* (app) {\n-    let addons = yield this.heroku.request({path: `/apps/${app.name}/addons`});\n-    return _.partition(addons, function (addon) {\n-      return addon.plan.name.startsWith('heroku-postgresql');\n-    });\n+  attachAddon: function* (app, addon, attachment) {\n+    try {\n+      process.stdout.write(`Attaching addon ${cli.color.magenta(attachment.name)} from ${cli.color.cyan(addon.app.name)} to ${cli.color.cyan(app.name)} as ${cli.color.green(attachment.name)}... `);\n+      attachment = yield this.heroku.addonAttachments().create({addon: addon.id, app: app.id, name: attachment.name});\n+      console.log('done');\n+      return attachment;\n+    } catch (err) {\n+      console.error(`Skipped attachment ${cli.color.magenta(attachment.name)}`);\n+      if (err.body) cli.error(err.body.message);\n+      else          cli.error(err);\n+    }\n   },\n \n   copyAddons: function* (oldApp, newApp, skipPG) {\n-    let allAddons = yield this.getAddons(oldApp);\n-    let pgdbs = allAddons[0];\n-    let addons = allAddons[1];\n-    if (addons.length > 0) {\n-      for (let addon of addons) {\n-        yield this.addAddon(newApp, addon);\n-      }\n-    }\n-    if (!skipPG && pgdbs.length > 0) {\n-      let fromConfig = yield this.heroku.apps(oldApp.name).configVars().info();\n-      for (let db of pgdbs) {\n-        let toDB = yield this.addAddon(newApp, db);\n+    let addons = yield this.heroku.get(`/apps/${oldApp.name}/addons`);\n+    let attachments = yield this.heroku.get(`/apps/${oldApp.name}/addon-attachments`);\n+    for (let attachment of attachments) {\n+      /*jshint -W083 */\n+      let addon = addons.find(a => a.id === attachment.addon.id);\n+      if (addon.plan.name.startsWith('heroku-postgresql')) {\n+        if (skipPG) continue;\n+        let fromConfig = yield this.heroku.apps(oldApp.name).configVars().info();\n+        let toDB = yield this.addAddon(newApp, addon, attachment);\n         if (toDB) {\n           let toConfig = yield this.heroku.apps(newApp.name).configVars().info();\n-          yield this.postgres.migrateDB(fromConfig, db, toConfig, toDB);\n+          yield this.postgres.migrateDB(fromConfig, addon, toConfig, toDB);\n         }\n+      } else if (addon.app.name !== oldApp.name) {\n+        yield this.attachAddon(newApp, addon, attachment);\n+      } else {\n+        yield this.addAddon(newApp, addon, attachment);","path":"lib/addons.js","position":85,"original_position":83,"commit_id":"7eeb480b2e04c192937e0be3d3c2155e45c3c9e2","original_commit_id":"949a6ec4c8f99645cdde296c5e8aef23139102ba","user":{"login":"bjeanes","id":2560,"avatar_url":"https://avatars.githubusercontent.com/u/2560?v=3","gravatar_id":"","url":"https://api.github.com/users/bjeanes","html_url":"https://github.com/bjeanes","followers_url":"https://api.github.com/users/bjeanes/followers","following_url":"https://api.github.com/users/bjeanes/following{/other_user}","gists_url":"https://api.github.com/users/bjeanes/gists{/gist_id}","starred_url":"https://api.github.com/users/bjeanes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bjeanes/subscriptions","organizations_url":"https://api.github.com/users/bjeanes/orgs","repos_url":"https://api.github.com/users/bjeanes/repos","events_url":"https://api.github.com/users/bjeanes/events{/privacy}","received_events_url":"https://api.github.com/users/bjeanes/received_events","type":"User","site_admin":false},"body":"```\r\n$ heroku apps:create -a toomanyforkeddbs\r\n$ heroku addons:create heroku-redis --name theredistofork -a toomanyforkeddbs\r\n$ heroku addons:attach theredistofork -a toomanyforkeddbs\r\n$ heroku addons:attach theredistofork -a toomanyforkeddbs\r\n$ heroku addons:attach theredistofork -a toomanyforkeddbs\r\n$ heroku fork -a toomanyforkeddbs\r\n```\r\n\r\nThat'll probably create a bunch of DBs when forked.","created_at":"2016-01-28T04:21:54Z","updated_at":"2016-01-28T04:21:54Z","html_url":"https://github.com/heroku/heroku-fork/pull/11#discussion_r51078406","pull_request_url":"https://api.github.com/repos/heroku/heroku-fork/pulls/11","_links":{"self":{"href":"https://api.github.com/repos/heroku/heroku-fork/pulls/comments/51078406"},"html":{"href":"https://github.com/heroku/heroku-fork/pull/11#discussion_r51078406"},"pull_request":{"href":"https://api.github.com/repos/heroku/heroku-fork/pulls/11"}}},"pull_request":{"url":"https://api.github.com/repos/heroku/heroku-fork/pulls/11","id":57451939,"html_url":"https://github.com/heroku/heroku-fork/pull/11","diff_url":"https://github.com/heroku/heroku-fork/pull/11.diff","patch_url":"https://github.com/heroku/heroku-fork/pull/11.patch","issue_url":"https://api.github.com/repos/heroku/heroku-fork/issues/11","number":11,"state":"open","locked":false,"title":"properly attach addons","user":{"login":"dickeyxxx","id":216188,"avatar_url":"https://avatars.githubusercontent.com/u/216188?v=3","gravatar_id":"","url":"https://api.github.com/users/dickeyxxx","html_url":"https://github.com/dickeyxxx","followers_url":"https://api.github.com/users/dickeyxxx/followers","following_url":"https://api.github.com/users/dickeyxxx/following{/other_user}","gists_url":"https://api.github.com/users/dickeyxxx/gists{/gist_id}","starred_url":"https://api.github.com/users/dickeyxxx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dickeyxxx/subscriptions","organizations_url":"https://api.github.com/users/dickeyxxx/orgs","repos_url":"https://api.github.com/users/dickeyxxx/repos","events_url":"https://api.github.com/users/dickeyxxx/events{/privacy}","received_events_url":"https://api.github.com/users/dickeyxxx/received_events","type":"User","site_admin":false},"body":"* keep addon attachment name when creating new addons\n* re-attach attached addons to forked app\n* added more output\n* added color","created_at":"2016-01-28T03:53:44Z","updated_at":"2016-01-28T04:21:54Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3275d249260f13751627242d509b44412a192a8f","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/heroku/heroku-fork/pulls/11/commits","review_comments_url":"https://api.github.com/repos/heroku/heroku-fork/pulls/11/comments","review_comment_url":"https://api.github.com/repos/heroku/heroku-fork/pulls/comments{/number}","comments_url":"https://api.github.com/repos/heroku/heroku-fork/issues/11/comments","statuses_url":"https://api.github.com/repos/heroku/heroku-fork/statuses/7eeb480b2e04c192937e0be3d3c2155e45c3c9e2","head":{"label":"heroku:attachments","ref":"attachments","sha":"7eeb480b2e04c192937e0be3d3c2155e45c3c9e2","user":{"login":"heroku","id":23211,"avatar_url":"https://avatars.githubusercontent.com/u/23211?v=3","gravatar_id":"","url":"https://api.github.com/users/heroku","html_url":"https://github.com/heroku","followers_url":"https://api.github.com/users/heroku/followers","following_url":"https://api.github.com/users/heroku/following{/other_user}","gists_url":"https://api.github.com/users/heroku/gists{/gist_id}","starred_url":"https://api.github.com/users/heroku/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/heroku/subscriptions","organizations_url":"https://api.github.com/users/heroku/orgs","repos_url":"https://api.github.com/users/heroku/repos","events_url":"https://api.github.com/users/heroku/events{/privacy}","received_events_url":"https://api.github.com/users/heroku/received_events","type":"Organization","site_admin":false},"repo":{"id":30686429,"name":"heroku-fork","full_name":"heroku/heroku-fork","owner":{"login":"heroku","id":23211,"avatar_url":"https://avatars.githubusercontent.com/u/23211?v=3","gravatar_id":"","url":"https://api.github.com/users/heroku","html_url":"https://github.com/heroku","followers_url":"https://api.github.com/users/heroku/followers","following_url":"https://api.github.com/users/heroku/following{/other_user}","gists_url":"https://api.github.com/users/heroku/gists{/gist_id}","starred_url":"https://api.github.com/users/heroku/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/heroku/subscriptions","organizations_url":"https://api.github.com/users/heroku/orgs","repos_url":"https://api.github.com/users/heroku/repos","events_url":"https://api.github.com/users/heroku/events{/privacy}","received_events_url":"https://api.github.com/users/heroku/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/heroku/heroku-fork","description":"Heroku CLI plugin to fork an existing app into a new app","fork":false,"url":"https://api.github.com/repos/heroku/heroku-fork","forks_url":"https://api.github.com/repos/heroku/heroku-fork/forks","keys_url":"https://api.github.com/repos/heroku/heroku-fork/keys{/key_id}","collaborators_url":"https://api.github.com/repos/heroku/heroku-fork/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/heroku/heroku-fork/teams","hooks_url":"https://api.github.com/repos/heroku/heroku-fork/hooks","issue_events_url":"https://api.github.com/repos/heroku/heroku-fork/issues/events{/number}","events_url":"https://api.github.com/repos/heroku/heroku-fork/events","assignees_url":"https://api.github.com/repos/heroku/heroku-fork/assignees{/user}","branches_url":"https://api.github.com/repos/heroku/heroku-fork/branches{/branch}","tags_url":"https://api.github.com/repos/heroku/heroku-fork/tags","blobs_url":"https://api.github.com/repos/heroku/heroku-fork/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/heroku/heroku-fork/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/heroku/heroku-fork/git/refs{/sha}","trees_url":"https://api.github.com/repos/heroku/heroku-fork/git/trees{/sha}","statuses_url":"https://api.github.com/repos/heroku/heroku-fork/statuses/{sha}","languages_url":"https://api.github.com/repos/heroku/heroku-fork/languages","stargazers_url":"https://api.github.com/repos/heroku/heroku-fork/stargazers","contributors_url":"https://api.github.com/repos/heroku/heroku-fork/contributors","subscribers_url":"https://api.github.com/repos/heroku/heroku-fork/subscribers","subscription_url":"https://api.github.com/repos/heroku/heroku-fork/subscription","commits_url":"https://api.github.com/repos/heroku/heroku-fork/commits{/sha}","git_commits_url":"https://api.github.com/repos/heroku/heroku-fork/git/commits{/sha}","comments_url":"https://api.github.com/repos/heroku/heroku-fork/comments{/number}","issue_comment_url":"https://api.github.com/repos/heroku/heroku-fork/issues/comments{/number}","contents_url":"https://api.github.com/repos/heroku/heroku-fork/contents/{+path}","compare_url":"https://api.github.com/repos/heroku/heroku-fork/compare/{base}...{head}","merges_url":"https://api.github.com/repos/heroku/heroku-fork/merges","archive_url":"https://api.github.com/repos/heroku/heroku-fork/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/heroku/heroku-fork/downloads","issues_url":"https://api.github.com/repos/heroku/heroku-fork/issues{/number}","pulls_url":"https://api.github.com/repos/heroku/heroku-fork/pulls{/number}","milestones_url":"https://api.github.com/repos/heroku/heroku-fork/milestones{/number}","notifications_url":"https://api.github.com/repos/heroku/heroku-fork/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/heroku/heroku-fork/labels{/name}","releases_url":"https://api.github.com/repos/heroku/heroku-fork/releases{/id}","deployments_url":"https://api.github.com/repos/heroku/heroku-fork/deployments","created_at":"2015-02-12T04:58:19Z","updated_at":"2016-01-27T16:58:32Z","pushed_at":"2016-01-28T04:05:53Z","git_url":"git://github.com/heroku/heroku-fork.git","ssh_url":"git@github.com:heroku/heroku-fork.git","clone_url":"https://github.com/heroku/heroku-fork.git","svn_url":"https://github.com/heroku/heroku-fork","homepage":"https://www.npmjs.com/package/heroku-fork","size":66,"stargazers_count":3,"watchers_count":3,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":3,"forks":0,"open_issues":3,"watchers":3,"default_branch":"master"}},"base":{"label":"heroku:master","ref":"master","sha":"76470c0970e5d653c0236766997b8ea5cb8de2d6","user":{"login":"heroku","id":23211,"avatar_url":"https://avatars.githubusercontent.com/u/23211?v=3","gravatar_id":"","url":"https://api.github.com/users/heroku","html_url":"https://github.com/heroku","followers_url":"https://api.github.com/users/heroku/followers","following_url":"https://api.github.com/users/heroku/following{/other_user}","gists_url":"https://api.github.com/users/heroku/gists{/gist_id}","starred_url":"https://api.github.com/users/heroku/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/heroku/subscriptions","organizations_url":"https://api.github.com/users/heroku/orgs","repos_url":"https://api.github.com/users/heroku/repos","events_url":"https://api.github.com/users/heroku/events{/privacy}","received_events_url":"https://api.github.com/users/heroku/received_events","type":"Organization","site_admin":false},"repo":{"id":30686429,"name":"heroku-fork","full_name":"heroku/heroku-fork","owner":{"login":"heroku","id":23211,"avatar_url":"https://avatars.githubusercontent.com/u/23211?v=3","gravatar_id":"","url":"https://api.github.com/users/heroku","html_url":"https://github.com/heroku","followers_url":"https://api.github.com/users/heroku/followers","following_url":"https://api.github.com/users/heroku/following{/other_user}","gists_url":"https://api.github.com/users/heroku/gists{/gist_id}","starred_url":"https://api.github.com/users/heroku/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/heroku/subscriptions","organizations_url":"https://api.github.com/users/heroku/orgs","repos_url":"https://api.github.com/users/heroku/repos","events_url":"https://api.github.com/users/heroku/events{/privacy}","received_events_url":"https://api.github.com/users/heroku/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/heroku/heroku-fork","description":"Heroku CLI plugin to fork an existing app into a new app","fork":false,"url":"https://api.github.com/repos/heroku/heroku-fork","forks_url":"https://api.github.com/repos/heroku/heroku-fork/forks","keys_url":"https://api.github.com/repos/heroku/heroku-fork/keys{/key_id}","collaborators_url":"https://api.github.com/repos/heroku/heroku-fork/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/heroku/heroku-fork/teams","hooks_url":"https://api.github.com/repos/heroku/heroku-fork/hooks","issue_events_url":"https://api.github.com/repos/heroku/heroku-fork/issues/events{/number}","events_url":"https://api.github.com/repos/heroku/heroku-fork/events","assignees_url":"https://api.github.com/repos/heroku/heroku-fork/assignees{/user}","branches_url":"https://api.github.com/repos/heroku/heroku-fork/branches{/branch}","tags_url":"https://api.github.com/repos/heroku/heroku-fork/tags","blobs_url":"https://api.github.com/repos/heroku/heroku-fork/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/heroku/heroku-fork/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/heroku/heroku-fork/git/refs{/sha}","trees_url":"https://api.github.com/repos/heroku/heroku-fork/git/trees{/sha}","statuses_url":"https://api.github.com/repos/heroku/heroku-fork/statuses/{sha}","languages_url":"https://api.github.com/repos/heroku/heroku-fork/languages","stargazers_url":"https://api.github.com/repos/heroku/heroku-fork/stargazers","contributors_url":"https://api.github.com/repos/heroku/heroku-fork/contributors","subscribers_url":"https://api.github.com/repos/heroku/heroku-fork/subscribers","subscription_url":"https://api.github.com/repos/heroku/heroku-fork/subscription","commits_url":"https://api.github.com/repos/heroku/heroku-fork/commits{/sha}","git_commits_url":"https://api.github.com/repos/heroku/heroku-fork/git/commits{/sha}","comments_url":"https://api.github.com/repos/heroku/heroku-fork/comments{/number}","issue_comment_url":"https://api.github.com/repos/heroku/heroku-fork/issues/comments{/number}","contents_url":"https://api.github.com/repos/heroku/heroku-fork/contents/{+path}","compare_url":"https://api.github.com/repos/heroku/heroku-fork/compare/{base}...{head}","merges_url":"https://api.github.com/repos/heroku/heroku-fork/merges","archive_url":"https://api.github.com/repos/heroku/heroku-fork/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/heroku/heroku-fork/downloads","issues_url":"https://api.github.com/repos/heroku/heroku-fork/issues{/number}","pulls_url":"https://api.github.com/repos/heroku/heroku-fork/pulls{/number}","milestones_url":"https://api.github.com/repos/heroku/heroku-fork/milestones{/number}","notifications_url":"https://api.github.com/repos/heroku/heroku-fork/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/heroku/heroku-fork/labels{/name}","releases_url":"https://api.github.com/repos/heroku/heroku-fork/releases{/id}","deployments_url":"https://api.github.com/repos/heroku/heroku-fork/deployments","created_at":"2015-02-12T04:58:19Z","updated_at":"2016-01-27T16:58:32Z","pushed_at":"2016-01-28T04:05:53Z","git_url":"git://github.com/heroku/heroku-fork.git","ssh_url":"git@github.com:heroku/heroku-fork.git","clone_url":"https://github.com/heroku/heroku-fork.git","svn_url":"https://github.com/heroku/heroku-fork","homepage":"https://www.npmjs.com/package/heroku-fork","size":66,"stargazers_count":3,"watchers_count":3,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":3,"forks":0,"open_issues":3,"watchers":3,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/heroku/heroku-fork/pulls/11"},"html":{"href":"https://github.com/heroku/heroku-fork/pull/11"},"issue":{"href":"https://api.github.com/repos/heroku/heroku-fork/issues/11"},"comments":{"href":"https://api.github.com/repos/heroku/heroku-fork/issues/11/comments"},"review_comments":{"href":"https://api.github.com/repos/heroku/heroku-fork/pulls/11/comments"},"review_comment":{"href":"https://api.github.com/repos/heroku/heroku-fork/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/heroku/heroku-fork/pulls/11/commits"},"statuses":{"href":"https://api.github.com/repos/heroku/heroku-fork/statuses/7eeb480b2e04c192937e0be3d3c2155e45c3c9e2"}}}}