Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate(W-14170373): Upgrade pg:backups:delete #2734

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
42 changes: 42 additions & 0 deletions packages/cli/src/commands/pg/backups/delete.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import color from '@heroku-cli/color'
import {Command, flags} from '@heroku-cli/command'
import {Args, ux} from '@oclif/core'
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}),
remote: flags.remote(),
}

static args = {
backup_id: Args.string({required: true}),
}

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.app(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 = {
canceled_at: string,
Expand Down
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/restore'),
require('./commands/backups/schedule'),
Expand Down
2 changes: 1 addition & 1 deletion packages/pg-v5/test/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ chai.use(chaiAsPromised)
let cli = require('heroku-cli-util') // Load heroku-cli-util helpers
cli.raiseErrors = true // Fully raise exceptions
process.env.TZ = 'UTC' // Use UTC time always

process.env.IS_DEV_ENVIRONMENT = 'true'
process.stdout.columns = 80
process.stderr.columns = 80

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
Loading