1 | 'use strict'
|
2 |
|
3 | const cli = require('heroku-cli-util')
|
4 | const co = require('co')
|
5 |
|
6 | function * run (context, heroku) {
|
7 | const host = require('../../lib/host')
|
8 | const util = require('../../lib/util')
|
9 | const fetcher = require('../../lib/fetcher')(heroku)
|
10 | const {app, args} = context
|
11 |
|
12 | const db = yield fetcher.addon(app, args.database)
|
13 |
|
14 | if (util.starterPlan(db)) throw new Error('This operation is not supported by Hobby tier databases.')
|
15 | if (util.legacyPlan(db)) throw new Error('This operation is not supported by Legacy-tier databases.')
|
16 |
|
17 | let settings = yield heroku.get(`/postgres/v0/databases/${db.id}/config`, {host: host(db)})
|
18 | cli.styledHeader(db.name)
|
19 | let remapped = Object.keys(settings).reduce((s, key) => {
|
20 | s[key.replace(/_/g, '-')] = settings[key]['value']
|
21 | return s
|
22 | }, {})
|
23 | cli.styledObject(remapped)
|
24 | }
|
25 |
|
26 | module.exports = {
|
27 | topic: 'pg',
|
28 | command: 'settings',
|
29 | description: 'show your current database settings',
|
30 | needsApp: true,
|
31 | needsAuth: true,
|
32 | args: [{name: 'database', optional: true}],
|
33 | run: cli.command({preauth: true}, co.wrap(run))
|
34 | }
|