UNPKG

1.15 kBJavaScriptView Raw
1'use strict'
2
3const cli = require('heroku-cli-util')
4
5async function run(context, heroku) {
6 const fetcher = require('../../lib/fetcher')(heroku)
7 const host = require('../../lib/host')
8 const util = require('../../lib/util')
9 const { app, args, flags } = context
10 const db = await fetcher.addon(app, args.database)
11
12 if (util.starterPlan(db)) throw new Error('pg:maintenance is only available for production databases')
13 await cli.action(`Starting maintenance for ${cli.color.addon(db.name)}`, async function () {
14 if (!flags.force) {
15 let appInfo = await heroku.get(`/apps/${app}`)
16 if (!appInfo.maintenance) throw new Error('Application must be in maintenance mode or run with --force')
17 }
18 let response = await heroku.post(`/client/v11/databases/${db.id}/maintenance`, { host: host(db) })
19 cli.action.done(response.message || 'done')
20 }())
21}
22
23module.exports = {
24 topic: 'pg',
25 command: 'maintenance:run',
26 description: 'start maintenance',
27 needsApp: true,
28 needsAuth: true,
29 args: [{ name: 'database', optional: true }],
30 flags: [{ name: 'force', char: 'f' }],
31 run: cli.command({ preauth: true }, run)
32}