Skip to content

feat(data): add database settings composites for v12 CLI - #193

Open
eablack wants to merge 4 commits into
mainfrom
eb/W-23389002/database-settings
Open

eablack wants to merge 4 commits into
mainfrom
eb/W-23389002/database-settings

Conversation

@eablack

@eablack eablack commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds data.databaseSettings.{getAll, get, update} so the v12 CLI's pg:settings commands can drop their own database resolution and their direct calls to /postgres/v0/databases/{id}/config.

  • getAll(appIdentity, databaseIdentity?, options?) returns {addon, settings}.
  • get(appIdentity, key, databaseIdentity?, options?) returns {addon, setting}.
  • update(appIdentity, key, value, databaseIdentity?, options?) sends only {[key]: value} and returns {addon, setting}.

Each one resolves the database through resolvePgDatabase (DATABASE_URL by default) and rejects Essential-tier databases with EssentialDatabaseNotSupportedError before calling the config endpoint. get and update throw a new UnknownSettingError (id unknown_database_setting) when the response doesn't include the key. The endpoint only returns the keys the database's tier supports.

Notes:

  • It's a new databaseSettings resource, not database.settings, because extensions add methods to a resource and can't add nested objects.
  • PostgresDatabaseUpdateConfigOpts in @heroku/types lists only 3 of the keys the endpoint accepts, so update casts the body. The key and value types come from PostgresDatabaseConfigResult, which lists every key.

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:
The CLI side is in heroku/cli on branch eb/W-23389002/pg-settings-sdk. You need a non-Essential Heroku Postgres database to try it.

Steps:

  1. npm run build, then in a script: const sdk = new HerokuSDK({extensions: [databaseSettingsExtensions]}).
  2. await sdk.data.databaseSettings.getAll('<app>') returns the DATABASE_URL database's add-on and every setting.
  3. await sdk.data.databaseSettings.get('<app>', 'log_lock_waits') returns that one setting.
  4. await sdk.data.databaseSettings.update('<app>', 'log_lock_waits', true) returns the updated setting. Set it back afterward.
  5. Against an Essential-tier database, each call throws EssentialDatabaseNotSupportedError without calling the config endpoint.

Related Issues

GUS work item: W-23389002

Adds data.databaseSettings.{getAll, get, update}. Each resolves the
Postgres database (DATABASE_URL by default), rejects Essential-tier
databases with EssentialDatabaseNotSupportedError, and returns the
resolved add-on with the settings. get/update throw UnknownSettingError
when the database's settings don't include the key.

W-23389002
- Reject Advanced-tier databases with AdvancedDatabaseNotSupportedError
  before any settings request; those databases use data.postgresSettings.
  Doc comments now say the resource covers classic tiers.
- Rename UnknownSettingError to UnknownDatabaseSettingError to match its
  id and the other database error names.
- Add `key` to get/update results so the result says which setting it is.
- When an update response lacks the key, say the update was sent but
  couldn't be confirmed, instead of saying the setting doesn't exist.
- Treat a setting as missing only when it's undefined.
- Add the ./resources/data/database-settings package export, like the
  sibling data resources.
- Tests: pin the database identity and signal for get/update and the
  resolver, aborted update sends nothing, falsy values, Advanced-tier
  rejection, and end-to-end wiring against the real request URLs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant