1 | 'use strict'
|
2 |
|
3 | const cli = require('heroku-cli-util')
|
4 | const host = require('../lib/host')
|
5 |
|
6 | async function run(context, heroku) {
|
7 | const util = require('../lib/util')
|
8 | const fetcher = require('../lib/fetcher')(heroku)
|
9 | const { app, args, flags } = context
|
10 |
|
11 | let db = await fetcher.addon(app, args.database)
|
12 | let addon = await heroku.get(`/addons/${encodeURIComponent(db.name)}`)
|
13 |
|
14 | if (util.starterPlan(db)) throw new Error('This operation is not supported by Hobby tier databases.')
|
15 |
|
16 | let attachment = await cli.action(
|
17 | `Enabling Connection Pooling on ${cli.color.addon(addon.name)} to ${cli.color.app(app)}`,
|
18 | heroku.post(`/client/v11/databases/${encodeURIComponent(db.name)}/connection-pooling`, {
|
19 | body: { name: flags.as, credential: 'default', app: app },
|
20 | host: host(db)
|
21 | })
|
22 | )
|
23 |
|
24 | await cli.action(
|
25 | `Setting ${cli.color.attachment(attachment.name)} config vars and restarting ${cli.color.app(app)}`,
|
26 | { success: false },
|
27 | async function () {
|
28 | let releases = await heroku.get(`/apps/${app}/releases`, {
|
29 | partial: true,
|
30 | headers: { 'Range': 'version ..; max=1, order=desc' }
|
31 | })
|
32 | cli.action.done(`done, v${releases[0].version}`)
|
33 | }()
|
34 | )
|
35 | }
|
36 |
|
37 | module.exports = {
|
38 | topic: 'pg',
|
39 | command: 'connection-pooling:attach',
|
40 | description: 'add an attachment to a database using connection pooling',
|
41 | needsApp: true,
|
42 | needsAuth: true,
|
43 | help: `Example:
|
44 |
|
45 | heroku pg:connection-pooling:attach postgresql-something-12345
|
46 | `,
|
47 | args: [{ name: 'database', optional: true }],
|
48 | flags: [
|
49 | { name: 'as', description: 'name for add-on attachment', hasValue: true }
|
50 | ],
|
51 | run: cli.command({ preauth: true }, run)
|
52 | }
|