UNPKG

1.26 kBJavaScriptView Raw
1'use strict'
2
3const cli = require('heroku-cli-util')
4
5async function run(context, heroku) {
6 const host = require('../lib/host')
7 const util = require('../lib/util')
8 const fetcher = require('../lib/fetcher')(heroku)
9 let { app, args, flags } = context
10 let db = await fetcher.addon(app, args.database)
11
12 let replica = await heroku.get(`/client/v11/databases/${db.id}`, { host: host(db) })
13
14 if (!replica.following) throw new Error(`${cli.color.addon(db.name)} is not a follower`)
15
16 let origin = util.databaseNameFromUrl(replica.following, await heroku.get(`/apps/${app}/config-vars`))
17 await cli.confirmApp(app, flags.confirm, `WARNING: Destructive action
18${cli.color.addon(db.name)} will become writeable and no longer follow ${origin}. This cannot be undone.
19`)
20
21 await cli.action(`${cli.color.addon(db.name)} unfollowing`, async function () {
22 await heroku.put(`/client/v11/databases/${db.id}/unfollow`, { host: host(db) })
23 }())
24}
25
26module.exports = {
27 topic: 'pg',
28 command: 'unfollow',
29 description: 'stop a replica from following and make it a writeable database',
30 needsApp: true,
31 needsAuth: true,
32 args: [{ name: 'database' }],
33 flags: [{ name: 'confirm', char: 'c', hasValue: true }],
34 run: cli.command({ preauth: true }, run)
35}