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 | let replica = yield heroku.get(`/client/v11/databases/${db.id}`, {host: host(db)})
|
14 |
|
15 | if (!replica.following) throw new Error(`${cli.color.addon(db.name)} is not a follower`)
|
16 |
|
17 | let origin = util.databaseNameFromUrl(replica.following, yield heroku.get(`/apps/${app}/config-vars`))
|
18 | yield cli.confirmApp(app, flags.confirm, `WARNING: Destructive action
|
19 | ${cli.color.addon(db.name)} will become writeable and no longer follow ${origin}. This cannot be undone.
|
20 | `)
|
21 |
|
22 | yield cli.action(`${cli.color.addon(db.name)} unfollowing`, co(function * () {
|
23 | yield heroku.put(`/client/v11/databases/${db.id}/unfollow`, {host: host(db)})
|
24 | }))
|
25 | }
|
26 |
|
27 | module.exports = {
|
28 | topic: 'pg',
|
29 | command: 'unfollow',
|
30 | description: 'stop a replica from following and make it a writeable database',
|
31 | needsApp: true,
|
32 | needsAuth: true,
|
33 | args: [{name: 'database'}],
|
34 | flags: [{name: 'confirm', char: 'c', hasValue: true}],
|
35 | run: cli.command({preauth: true}, co.wrap(run))
|
36 | }
|