Skip to content

refactor: use @heroku/sdk for data:pg:credentials commands - #4017

Merged
erika-wallace merged 5 commits into
v12.0.0from
ew/sdk-data-pg-part2
Oct 28, 2026
Merged

erika-wallace merged 5 commits into
v12.0.0from
ew/sdk-data-pg-part2

Conversation

@erika-wallace

@erika-wallace erika-wallace commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR migrates the data:pg:credentials commands — create, destroy, index, rotate, url — to @heroku/sdk (part 2 of the data:pg subcommand migration, following #4001), replacing raw this.heroku/this.dataApi calls and heroku-cli-util's utils.AddonResolver/utils.pg helpers with the SDK's databaseCredentialExtensions.

Command Changes

  • create.ts, destroy.ts, index.ts, rotate.ts, and url.ts now call data.databaseCredential.{create,destroy,list,rotate,getUrl} via createSDK(this.heroku, {extensions: [databaseCredentialExtensions]}), instead of resolving the add-on and building REST paths by hand.
  • data:pg:credentials:index detects non-Advanced-tier databases via the SDK's NotAdvancedDatabaseError (instead of an explicit tier check before fetching credentials) and still suggests pg:credentials as before.
  • data:pg:credentials:rotate is restructured around a beforeRotate callback passed to data.databaseCredential.rotate, which now owns resolving credentials/attachments and building the confirmation preview; the command's private getCredsAndAttachments/getCredToRotate methods are removed since the SDK resolves and previews the rotation internally.
  • data:pg:credentials:url now reads credentialConnectionInfo.{database,host,port,user,password,url,credName} directly from data.databaseCredential.getUrl(...), instead of fetching raw credential info and building the postgres:// URL by hand.
  • Deleted src/lib/data/parse-attachment-factors.ts and its test — attachment-namespace parsing now comes from @heroku/sdk/resources/data/postgres-database's parseAttachmentFactors.

Test Changes

  • Unit tests for all five credential commands are migrated from nock to mockSDKData/mockSDK stubs (test/helpers/mock-sdk.ts), with mocked resolve/reject shapes to match the SDK's return types

V12-CHANGES.md

  • User-visible behavior changes: data:pg:credentials:url and data:pg:credentials:destroy error messages are now plain, uncolored text, since the SDK throws plain Errors for these cases.

Note: src/commands/data/pg/attachments/create.ts and src/commands/pg/credentials.ts aren't migrated in this PR, so their use of sortByLeaderAndName/sortByOwnerAndName/presentCredentialAttachments (previously imported from now-SDK-typed credential-utils.ts/lib/pg/util.ts) is temporarily inlined with a // TODO: Remove this once ... is migrated to use the SDK comment, to avoid taking on their migration here.

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 an Advanced-tier database and a classic (non-Essential) tier database.

Setup:

  1. Pull down this branch
  2. npm i && npm run build

Steps:

Advanced-tier database

  1. Create a credential. Verify the credential is created and the data:pg:attachments:create/pg:psql commands print with the right names
./bin/run data:pg:credentials:create ADVANCED_DATABASE --app APP --name my-credential
  1. List credentials. Verify the credential table renders with attachment and rotation-status columns, including my-credential
./bin/run data:pg:credentials ADVANCED_DATABASE --app APP
  1. Get a credential's connection URL. Verify the connection info string and connection URL both resolve to my-credential's host/port/user/password
./bin/run data:pg:credentials:url ADVANCED_DATABASE --app APP --name my-credential
  1. Rotate a single credential. Verify the confirmation prompt lists the affected apps and the credential rotates
./bin/run data:pg:credentials:rotate ADVANCED_DATABASE --app APP --name my-credential
  1. Rotate all credentials, forced. Verify the confirmation prompt mentions force-rotating and all credentials rotate
./bin/run data:pg:credentials:rotate ADVANCED_DATABASE --app APP --all --force
  1. Destroy a credential. Verify the credential destroys successfully
./bin/run data:pg:credentials:destroy ADVANCED_DATABASE --app APP --name my-credential
  1. List credentials. Verify my-credential is no longer listed
./bin/run data:pg:credentials ADVANCED_DATABASE --app APP

Classic (non-Essential) tier database

  1. Create a credential. Verify the credential is created and the addons:attach/pg:psql commands print with the right names
./bin/run data:pg:credentials:create CLASSIC_DATABASE --app APP --name my-credential
  1. List credentials. Verify the error suggests pg:credentials with the correct database name instead of listing credentials
./bin/run data:pg:credentials CLASSIC_DATABASE --app APP
  1. List credentials. Verify the credential table renders with attachment and rotation-status columns, including my-credential
./bin/run pg:credentials CLASSIC_DATABASE --app APP
  1. Get a credential's connection URL. Verify the connection info string and connection URL both resolve to my-credential's host/port/user/password
./bin/run data:pg:credentials:url CLASSIC_DATABASE --app APP --name my-credential
  1. Rotate a single credential. Verify the confirmation prompt lists the affected apps and the credential rotates
./bin/run data:pg:credentials:rotate CLASSIC_DATABASE --app APP --name my-credential
  1. Rotate all credentials, forced. Verify the confirmation prompt mentions force-rotating and all credentials rotate
./bin/run data:pg:credentials:rotate CLASSIC_DATABASE --app APP --all --force
  1. Destroy a credential. Verify the credential destroys successfully
./bin/run data:pg:credentials:destroy CLASSIC_DATABASE --app APP --name my-credential
  1. List credentials. Verify my-credential is no longer listed
./bin/run pg:credentials CLASSIC_DATABASE --app APP

Screenshots (if applicable)

Related Issues

GUS work item: W-23385448

@erika-wallace
erika-wallace requested a review from a team as a code owner October 27, 2026 16:25
@erika-wallace
erika-wallace deployed to AcceptanceTests October 27, 2026 16:25 — with GitHub Actions Active
@erika-wallace
erika-wallace deployed to AcceptanceTests October 27, 2026 16:25 — with GitHub Actions Active
@erika-wallace
erika-wallace deployed to AcceptanceTests October 27, 2026 16:25 — with GitHub Actions Active
@erika-wallace
erika-wallace deployed to AcceptanceTests October 27, 2026 16:25 — with GitHub Actions Active
@github-actions github-actions Bot added size/XL Extra large PR (code churn >= 1000); consider splitting docs Touches documentation labels Oct 27, 2026
@github-actions

Copy link
Copy Markdown

This PR is labeled size/XL (1988 lines of code churn, excluding docs, package-lock.json, and generated files).

Large PRs are harder to review well. If it can be split into smaller, independently reviewable pieces, consider doing so. This is a suggestion, not a blocker — the check still passes.

@erika-wallace
erika-wallace deployed to AcceptanceTests October 27, 2026 19:40 — with GitHub Actions Active
@erika-wallace
erika-wallace deployed to AcceptanceTests October 27, 2026 19:40 — with GitHub Actions Active
@erika-wallace
erika-wallace deployed to AcceptanceTests October 27, 2026 19:40 — with GitHub Actions Active
@erika-wallace
erika-wallace deployed to AcceptanceTests October 27, 2026 19:40 — with GitHub Actions Active
@erika-wallace
erika-wallace deployed to AcceptanceTests October 27, 2026 21:01 — with GitHub Actions Active
@erika-wallace
erika-wallace deployed to AcceptanceTests October 27, 2026 21:01 — with GitHub Actions Active
@erika-wallace
erika-wallace deployed to AcceptanceTests October 27, 2026 21:01 — with GitHub Actions Active
@erika-wallace
erika-wallace deployed to AcceptanceTests October 27, 2026 21:01 — with GitHub Actions Active

@jdodson jdodson 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.

Approved.

Manual tests all pass, good job.

AI had one thing it considers a blocker. Worth looking into.

  • Data-service configuration regression: migrated credential calls do not preserve the configured data host or HEROKU_DATA_CONTROL_PLANE header. This can break environments using those overrides.

@erika-wallace
erika-wallace deployed to AcceptanceTests October 27, 2026 22:11 — with GitHub Actions Active
@erika-wallace
erika-wallace deployed to AcceptanceTests October 27, 2026 22:11 — with GitHub Actions Active
@erika-wallace
erika-wallace deployed to AcceptanceTests October 27, 2026 22:11 — with GitHub Actions Active
@erika-wallace
erika-wallace deployed to AcceptanceTests October 27, 2026 22:11 — with GitHub Actions Active
@erika-wallace

Copy link
Copy Markdown
Contributor Author

Approved.

AI had one thing it considers a blocker. Worth looking into.

  • Data-service configuration regression: migrated credential calls do not preserve the configured data host or HEROKU_DATA_CONTROL_PLANE header. This can break environments using those overrides.

@jdodson This will be addressed in W-24610335

@erika-wallace
erika-wallace merged commit 39f4fd9 into v12.0.0 Oct 28, 2026
20 checks passed
@erika-wallace
erika-wallace deleted the ew/sdk-data-pg-part2 branch October 28, 2026 14:25

This branch was successfully deployed

1 active deployment
AcceptanceTests — 4be33d67 Deployed Oct 27, 2026 by erika-wallace via integration (22.x, ubuntu-latest) #9558
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Touches documentation size/XL Extra large PR (code churn >= 1000); consider splitting

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants