Skip to content

refactor: use @heroku/sdk for pg:backups commands (part 1) - #3958

Merged
erika-wallace merged 2 commits into
v12.0.0from
ew/sdk-pg-backups
Sep 28, 2026
Merged

erika-wallace merged 2 commits into
v12.0.0from
ew/sdk-pg-backups

Conversation

@erika-wallace

@erika-wallace erika-wallace commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR updates six pg:backups commands — pg:backups:cancel, pg:backups:delete, pg:backups:download, pg:backups, pg:backups:info, and pg:backups:url — to use the SDK instead of calling the Heroku API directly.

  • pg:backups:**: replaced manual this.heroku.get/post/delete calls with SDK calls to transfer.listByApp, transfer.infoByApp, transfer.cancel, transfer.deleteByApp, and transfer.publicUrl methods.
  • src/lib/pg/backups.ts: converted the Backups class into standalone named exports — filesize, name, num, status, and a new LogDisplay class extracted from the old displayLogs method.
  • Rewrote test files for the six migrated commands and src/lib/pg/backups.ts to mock the SDK

Note: src/lib/pg/backups.ts temporarily keeps its old default export (backupsFactory) and the poll/wait polling logic underneath a // TODO: Temporary... comment, since pg:backups:capture, pg:backups:restore, and pg:copy still depend on it and have not yet been migrated to the SDK. Those three commands, their schedule/schedules/unschedule siblings, and the corresponding lib cleanup are follow-up work.

Type of Change

Breaking Changes (major semver update)

  • Add a ! after your change type to denote a change that breaks current behavior

Feature Additions (minor semver update)

  • feat: Introduces a new feature to the codebase

Patch Updates (patch semver update)

  • fix: Bug fix
  • deps: Dependency upgrade
  • revert: Revert a previous commit
  • chore: Change that does not affect production code
  • refactor: Refactoring existing code without changing behavior
  • test: Add/update/remove tests

Testing

Notes:

Requires access to a Heroku app with a Postgres addon that has at least one backup captured (heroku pg:backups:capture --app APP).

Setup:

  1. Pull down this branch
  2. npm i && npm run build
  3. heroku logout && HEROKU_NETRC_WRITE=true ./bin/run login

Steps:

  1. Verify the Backups/Copies/Restores tables render
./bin/run pg:backups --app APP
  1. Verify the backup's details and logs display correctly
# Most recent backup
./bin/run pg:backups:info --app APP

# Specific backup based on id
./bin/run pg:backups:info BACKUP_ID --app APP
  1. Verify the download URL displays correctly
# Most recent backup
./bin/run pg:backups:url --app APP

# Specific backup based on id
./bin/run pg:backups:url BACKUP_ID --app APP
  1. Verify the backup downloads
# Most recent backup downloads to `latest.dump`
./bin/run pg:backups:download --app APP
test -f latest.dump && echo "found" || echo "not found"

# Specific backup downloads to the given output path
./bin/run pg:backups:download BACKUP_ID --app APP -o backup.dump
test -f backup.dump && echo "found" || echo "not found"
  1. Verify a specified backup is deleted
./bin/run pg:backups:delete BACKUP_ID --app APP --confirm APP
./bin/run pg:backups --app APP # Backup should no longer be listed
  1. Verify an in-progress backup is cancelled — Requires two separate terminals. A small backup can finish before cancel runs, so terminal 2 may still report "No active backups/transfers".
# Run in terminal 1
./bin/run pg:backups:capture --app APP

# Run in terminal 2, after terminal 1 shows "Backing up …"
./bin/run pg:backups:cancel --app APP

Cleanup:

  • rm backup.dump latest.dump
  • ./bin/run logout

Screenshots (if applicable)

Related Issues

GUS work item: W-23386457

@tlowrimore-heroku tlowrimore-heroku left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@erika-wallace
erika-wallace merged commit 67cc646 into v12.0.0 Sep 28, 2026
25 checks passed
@erika-wallace
erika-wallace deleted the ew/sdk-pg-backups branch September 28, 2026 19:56

This branch was successfully deployed

1 active deployment
AcceptanceTests — 788d5c31 Deployed Sep 28, 2026 by erika-wallace via acceptance (22.x, ubuntu-latest) #9347
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/L Large PR (code churn < 1000)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants