$ heroku addons:create heroku-postgresql:hobby-dev -a dog
Creating postgresql-opaque-93277... done, (free)
Adding postgresql-opaque-93277 to dog... done
Setting DATABASE_URL and restarting dog... done, v10
Database has been created and is available
$ heroku addons -a dog
Add-on Plan Price
─────────────────────────────────────────── ───────── ─────
heroku-postgresql (postgresql-opaque-93277) hobby-dev free
└─ as DATABASE
$ heroku addons:attach -a cat postgresql-opaque-93277
Attaching postgresql-opaque-93277 to cat... done
Setting DATABASE vars and restarting cat... done, v17
$ heroku addons -a cat
Add-on Plan Price
─────────────────────────────────────────── ───────── ────────────────────
heroku-postgresql (postgresql-opaque-93277) hobby-dev (billed to dog app)
├─ as DATABASE
└─ as DATABASE on dog app
DBの設定内容は、環境変数のDATABASE_URLに保存されている。
heorkuのダッシュボード上では以下のように共有されている事がわかるようになっている。
アドオンの削除
共有の解除
共有の解除は、detachを使う。
123
$ heroku addons:detach -a cat postgresql-opaque-93277
Removing DATABASE attachment to postgresql-opaque-93277 from cat... done
Unsetting DATABASE vars and restarting cat... done, v18
$ heroku addons:destroy postgresql-opaque-93277
! WARNING: Destructive Action
! This command will affect the app: dog
! To proceed, type "dog" or re-run this command with --confirm dog
> dog
Destroying postgresql-opaque-93277 on dog... done, (free)
Removing vars for DATABASE from dog and restarting... done, v13
$ heroku addons:create heroku-postgresql:hobby-dev -a dog --name dog-database --as DOG_DATABASE
Creating dog-database... done, (free)
Adding dog-database to dog... done
Setting DOG_DATABASE_URL and restarting dog... done, v16
Database has been created and is available
$ heroku config -a dog
=== dog Config Vars
DOG_DATABASE_URL: postgres://yo....
共有時
共有時にはアドオンの名前は設定出来ない(元を参照するので)が、asの指定は可能。
123
$ heroku addons:attach -a cat dog-database --as CAT_DATABASE
Attaching dog-database as CAT_DATABASE to cat... done
Setting CAT_DATABASE vars and restarting cat... done, v19