UNPKG

1.26 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 } = 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
14 if (!args.window.match(/^[A-Za-z]{2,10} \d\d?:[03]0$/)) throw new Error('Window must be "Day HH:MM" where MM is 00 or 30')
15
16 await cli.action(`Setting maintenance window for ${cli.color.addon(db.name)} to ${cli.color.cyan(args.window)}`, async function () {
17 let response = await heroku.put(`/client/v11/databases/${db.id}/maintenance_window`, {
18 body: { description: args.window },
19 host: host(db)
20 })
21 cli.action.done(response.message || 'done')
22 }())
23}
24
25module.exports = {
26 topic: 'pg',
27 command: 'maintenance:window',
28 description: 'set weekly maintenance window',
29 help: `All times are in UTC.
30
31Example:
32
33 heroku pg:maintenance:window postgres-slippery-100 "Sunday 06:00"`,
34 needsApp: true,
35 needsAuth: true,
36 args: [{ name: 'database' }, { name: 'window' }],
37 run: cli.command({ preauth: true }, run)
38}