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 | let {app, args, flags} = context
|
11 | let db = yield fetcher.addon(app, args.database)
|
12 |
|
13 | if (util.starterPlan(db)) throw new Error('pg:upgrade is only available for follower production databases')
|
14 |
|
15 | let [replica, status] = yield [
|
16 | heroku.get(`/client/v11/databases/${db.id}`, {host: host(db)}),
|
17 | heroku.get(`/client/v11/databases/${db.id}/upgrade_status`, {host: host(db)})
|
18 | ]
|
19 |
|
20 | if (status.error) throw new Error(status.error)
|
21 | let origin = util.databaseNameFromUrl(replica.following, yield heroku.get(`/apps/${app}/config-vars`))
|
22 |
|
23 | yield cli.confirmApp(app, flags.confirm, `WARNING: Destructive action
|
24 | ${cli.color.addon(db.name)} will be upgraded to a newer PostgreSQL version, stop following ${origin}, and become writable.
|
25 |
|
26 | This cannot be undone.`)
|
27 |
|
28 | yield cli.action(`Starting upgrade of ${cli.color.addon(db.name)}`, co(function * () {
|
29 | yield heroku.post(`/client/v11/databases/${db.id}/upgrade`, {host: host(db)})
|
30 | cli.action.done(`${cli.color.cmd('heroku pg:wait')} to track status`)
|
31 | }))
|
32 | }
|
33 |
|
34 | module.exports = {
|
35 | topic: 'pg',
|
36 | command: 'upgrade',
|
37 | description: 'unfollow a database and upgrade it to the latest stable PostgreSQL version',
|
38 | help: 'to upgrade to another PostgreSQL version, use pg:copy instead',
|
39 | needsApp: true,
|
40 | needsAuth: true,
|
41 | args: [{name: 'database', optional: true}],
|
42 | flags: [{name: 'confirm', char: 'c', hasValue: true}],
|
43 | run: cli.command({preauth: true}, co.wrap(run))
|
44 | }
|