-
Notifications
You must be signed in to change notification settings - Fork 234
Expand file tree
/
Copy pathwindow.js
More file actions
44 lines (34 loc) · 1.58 KB
/
window.js
File metadata and controls
44 lines (34 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
'use strict'
const cli = require('heroku-cli-util')
async function run(context, heroku) {
const fetcher = require('../../lib/fetcher')(heroku)
const host = require('../../lib/host')
const util = require('../../lib/util')
const {app, args} = context
const db = await fetcher.addon(app, args.database)
if (util.essentialPlan(db)) throw new Error('pg:maintenance isn’t available for Essential-tier databases.')
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')
let newPluginMessage = `You can also change the maintenance window with ${cli.color.cmd('data:maintenances:window:update')}.`
newPluginMessage += '\nFollow https://devcenter.heroku.com/articles/data-maintenance-cli-commands'
newPluginMessage += `\nto install the ${cli.color.bold.cyan('Data Maintenance CLI plugin')}.`
cli.warn(newPluginMessage)
await cli.action(`Setting maintenance window for ${cli.color.addon(db.name)} to ${cli.color.cyan(args.window)}`, (async function () {
let response = await heroku.put(`/client/v11/databases/${db.id}/maintenance_window`, {
body: {description: args.window},
host: host(db),
})
cli.action.done(response.message || 'done')
})())
}
module.exports = {
topic: 'pg',
command: 'maintenance:window',
description: 'set weekly maintenance window',
help: `All times are in UTC.
Example:
heroku pg:maintenance:window postgres-slippery-100 "Sunday 06:00"`,
needsApp: true,
needsAuth: true,
args: [{name: 'database'}, {name: 'window'}],
run: cli.command({preauth: true}, run),
}