UNPKG

1.57 kBJavaScriptView Raw
1'use strict'
2
3const co = require('co')
4const cli = require('heroku-cli-util')
5
6function * run (context, heroku) {
7 const host = require('../../lib/host')
8 const fetcher = require('../../lib/fetcher')(heroku)
9
10 const {app, args} = context
11 let db = args.database
12
13 if (!args.database) {
14 let appDB = yield fetcher.arbitraryAppDB(app)
15 let schedules = yield heroku.get(`/client/v11/databases/${appDB.id}/transfer-schedules`, {host: host(appDB)})
16 if (!schedules.length) throw new Error(`No schedules on ${cli.color.app(app)}`)
17 if (schedules.length > 1) {
18 throw new Error(`Specify schedule on ${cli.color.app(app)}. Existing schedules: ${schedules.map(s => cli.color.configVar(s.name)).join(', ')}`)
19 }
20 db = schedules[0].name
21 }
22
23 yield cli.action(`Unscheduling ${cli.color.configVar(db)} daily backups`, co(function * () {
24 let addon = yield fetcher.addon(app, db)
25 let schedules = yield heroku.get(`/client/v11/databases/${addon.id}/transfer-schedules`, {host: host(addon)})
26 let schedule = schedules.find(s => s.name.match(new RegExp(db, 'i')))
27 if (!schedule) throw new Error(`No daily backups found for ${cli.color.addon(addon.name)}`)
28 yield heroku.delete(`/client/v11/databases/${addon.id}/transfer-schedules/${schedule.uuid}`, {
29 host: host(addon)
30 })
31 }))
32}
33
34module.exports = {
35 topic: 'pg',
36 command: 'backups:unschedule',
37 description: 'stop daily backups',
38 needsApp: true,
39 needsAuth: true,
40 args: [
41 {name: 'database', optional: true}
42 ],
43 run: cli.command({preauth: true}, co.wrap(run))
44}