-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migrate(W-14170373): Upgrade pg:backups:delete
- Loading branch information
1 parent
858f70e
commit 5a7cdad
Showing
9 changed files
with
76 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,42 @@ | ||
import color from '@heroku-cli/color' | ||
import {Command, flags} from '@heroku-cli/command' | ||
import {Args, ux} from '@oclif/core' | ||
import * as Heroku from '@heroku-cli/schema' | ||
import {host} from '../lib/host' | ||
import confirmApp from '../../../lib/apps/confirm-app' | ||
import host from '../../../lib/pg/host' | ||
import backupsFactory from '../../../lib/pg/backups' | ||
|
||
export default class Delete extends Command { | ||
static topic = 'pg'; | ||
static description = 'delete a backup'; | ||
static flags = { | ||
confirm: flags.string({char: 'c'}), | ||
app: flags.app({required: true}), | ||
}; | ||
static topic = 'pg' | ||
static description = 'delete a backup' | ||
static flags = { | ||
confirm: flags.string({char: 'c'}), | ||
app: flags.app({required: true}), | ||
remote: flags.remote(), | ||
} | ||
|
||
static args = { | ||
backup_id: Args.string({required: true}), | ||
}; | ||
static args = { | ||
backup_id: Args.string({required: true}), | ||
} | ||
|
||
public async run(): Promise<void> { | ||
const {flags, argv, args} = await this.parse(Delete) | ||
const pgbackups = require('../../lib/pgbackups')(context, heroku) | ||
const {app, args, flags} = context | ||
await cli.confirmApp(app, flags.confirm) | ||
await ux.action(`Deleting backup ${color.cyan(args.backup_id)} on ${color.magenta(app)}`, (async function () { | ||
let num = await pgbackups.transfer.num(args.backup_id) | ||
if (!num) | ||
throw new Error(`Invalid Backup: ${args.backup_id}`) | ||
await this.heroku.delete(`/client/v11/apps/${app}/transfers/${num}`, {host}) | ||
})()) | ||
static examples = [ | ||
'$ heroku pg:backup:delete --app APP_ID BACKUP_ID', | ||
] | ||
|
||
public async run(): Promise<void> { | ||
const {flags, args} = await this.parse(Delete) | ||
const {app, confirm} = flags | ||
const {backup_id} = args | ||
const pgbackups = backupsFactory(app, this.heroku) | ||
|
||
await confirmApp(app, confirm) | ||
ux.action.start(`Deleting backup ${color.cyan(backup_id)} on ${color.magenta(app)}`) | ||
|
||
const num = await pgbackups.transfer.num(backup_id) | ||
if (!num) { | ||
throw new Error(`Invalid Backup: ${backup_id}`) | ||
} | ||
|
||
await this.heroku.delete(`/client/v11/apps/${app}/transfers/${num}`, {hostname: host()}) | ||
ux.action.stop() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 0 additions & 40 deletions
40
packages/cli/test/unit/commands/backups/delete.unit.test.ts
This file was deleted.
Oops, something went wrong.
33 changes: 33 additions & 0 deletions
33
packages/cli/test/unit/commands/pg/backups/delete.unit.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import {stderr} from 'stdout-stderr' | ||
import Cmd from '../../../../../src/commands/pg/backups/delete' | ||
import runCommand from '../../../../helpers/runCommand' | ||
import {expect} from 'chai' | ||
import * as nock from 'nock' | ||
|
||
describe('pg:backups:delete', () => { | ||
let pg: nock.Scope | ||
|
||
beforeEach(() => { | ||
pg = nock('https://api.data.heroku.com') | ||
.delete('/client/v11/apps/myapp/transfers/3') | ||
.reply(200, { | ||
url: 'https://dburl', | ||
}) | ||
}) | ||
|
||
afterEach(() => { | ||
nock.cleanAll() | ||
pg.done() | ||
}) | ||
|
||
it('shows URL', async () => { | ||
await runCommand(Cmd, [ | ||
'--app', | ||
'myapp', | ||
'--confirm', | ||
'myapp', | ||
'b003', | ||
]) | ||
expect(stderr.output).to.equal('Deleting backup b003 on myapp...\nDeleting backup b003 on myapp... done\n') | ||
}) | ||
}) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 0 additions & 37 deletions
37
packages/pg-v5/test/unit/commands/backups/delete.unit.test.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters