Skip to content

Commit

Permalink
migrate(W-14170373): Upgrade pg:backups:delete
Browse files Browse the repository at this point in the history
  • Loading branch information
justinwilaby committed Mar 21, 2024
1 parent 858f70e commit 5a7cdad
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 131 deletions.
1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
"@heroku-cli/schema": "^1.0.25",
"@oclif/test": "^2.3.25",
"@types/ansi-styles": "^3.2.1",
"@types/bytes": "^3.1.4",
"@types/chai": "^4.1.7",
"@types/chai-as-promised": "^7.1.8",
"@types/debug": "^4.1.2",
Expand Down
55 changes: 33 additions & 22 deletions packages/cli/src/commands/pg/backups/delete.ts
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()
}
}
2 changes: 1 addition & 1 deletion packages/cli/src/lib/pg/backups.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {APIClient} from '@heroku-cli/command'
import pgHost from './host'
const bytes = require('bytes')
import bytes = require('bytes')

export type BackupTransfer = {
num: number,
Expand Down
40 changes: 0 additions & 40 deletions packages/cli/test/unit/commands/backups/delete.unit.test.ts

This file was deleted.

33 changes: 33 additions & 0 deletions packages/cli/test/unit/commands/pg/backups/delete.unit.test.ts
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')
})
})
30 changes: 0 additions & 30 deletions packages/pg-v5/commands/backups/delete.js

This file was deleted.

1 change: 0 additions & 1 deletion packages/pg-v5/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ exports.commands = flatten([
require('./commands/backups'),
require('./commands/backups/cancel'),
require('./commands/backups/capture'),
require('./commands/backups/delete'),
require('./commands/backups/download'),
require('./commands/backups/info'),
require('./commands/backups/restore'),
Expand Down
37 changes: 0 additions & 37 deletions packages/pg-v5/test/unit/commands/backups/delete.unit.test.js

This file was deleted.

8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5037,6 +5037,13 @@ __metadata:
languageName: node
linkType: hard

"@types/bytes@npm:^3.1.4":
version: 3.1.4
resolution: "@types/bytes@npm:3.1.4"
checksum: 645732b37404847df9db7ae2af8b4bbdc21c966e9bbf8a5494d7fa95cbaee8bd7b9d65c68bbc2ec4277856d874e2e011b3b2b9479d981cd57d5136b0f41526e9
languageName: node
linkType: hard

"@types/cacheable-request@npm:^6.0.1":
version: 6.0.3
resolution: "@types/cacheable-request@npm:6.0.3"
Expand Down Expand Up @@ -10971,6 +10978,7 @@ __metadata:
"@opentelemetry/sdk-trace-node": ^1.15.1
"@opentelemetry/semantic-conventions": ^1.15.1
"@types/ansi-styles": ^3.2.1
"@types/bytes": ^3.1.4
"@types/chai": ^4.1.7
"@types/chai-as-promised": ^7.1.8
"@types/debug": ^4.1.2
Expand Down

0 comments on commit 5a7cdad

Please sign in to comment.