import type { AddOn } from '@heroku/types/3.sdk'; import type { PostgresPoolCreateResult, PostgresRunUpgradeOpts, PostgresRunUpgradeResult, PostgresWaitStatusResult } from '@heroku/types/data'; import type { ResourceCtx } from '../../core/extend-resource.js'; import type { ResolvedAddOn } from '../platform/add-on/types.js'; import type { ResolvedPgDatabase } from './internal/resolve-pg-database.js'; export type RunUpgradeOptions = { beforeRunUpgrade?: (preview: { addon: ResolvedPgDatabase; currentVersion: string; }) => Promise | void; signal?: AbortSignal; }; export type RunUpgradeResult = { addon: ResolvedPgDatabase; result: PostgresRunUpgradeResult; }; /** * Resolves a Postgres database by attachment identity and runs a version upgrade. * * Throws `NotAdvancedDatabaseError` (carrying the resolved add-on) if the * database isn't an Advanced-tier database. If provided, `beforeRunUpgrade` * runs after resolution/tier-checking (and the current-version lookup) but * before the upgrade request fires; an abort during the hook prevents the * upgrade. */ export declare function runUpgrade(ctx: Pick, appIdentity: string, addonIdentity?: string, body?: PostgresRunUpgradeOpts, options?: RunUpgradeOptions): Promise; export type WaitForReadyOptions = { /** * How many 404s from `wait_status` to tolerate as "still provisioning" * before rethrowing. Defaults to 20; this is a total budget across the whole * wait, not reset between polls. */ notFoundRetries?: number; /** * Fires once per poll with the latest status (including the synthetic * "still provisioning" status produced while the endpoint 404s), letting * callers surface a live progress message. */ onPoll?: (status: PostgresWaitStatusResult) => void; /** * Fires once the database is resolved and tier-checked, before the wait * poll begins, letting callers label a spinner with the resolved add-on * (mirrors `provisionAdvanced`/`fork`'s `onProvisioning`). An abort during * the hook prevents the poll. */ onResolved?: (addon: ResolvedPgDatabase) => Promise | void; /** * Aborts the in-flight request and any pending poll delay. */ signal?: AbortSignal; /** * Maximum total time to wait before throwing. Defaults to 1 hour as a * backstop against a `wait_status` that never reports ready; pass a larger * value for a legitimately longer wait, or `Infinity` to poll until the * database reports ready or `signal` aborts. */ timeoutMs?: number; /** * Polling interval in milliseconds. Defaults to 5000 (5s), matching the * CLI's historical `--wait-interval` default. Named `waitIntervalMs` to match * the SDK-wide wait-tuning convention (`platform.addOn`, `platform.domain`, * `data.postgresDatabase`). */ waitIntervalMs?: number; }; export type WaitForReadyResult = { addon: ResolvedPgDatabase; result: PostgresWaitStatusResult; }; export type ProvisionAdvancedBody = { /** Attachment name (`--as`). */ as?: string; /** * Extra provision options (parsed CLI `--provision-option` pairs). Merged * last, so these override `level`/`version`/`high-availability`. */ config?: Record; /** Confirmation value for a `confirmation_required` retry. */ confirm?: string; /** Number of follower pool instances to provision after the leader. */ followers?: number; /** Provision the leader with a high-availability standby. */ highAvailability?: boolean; /** Leader compute level (e.g. `advanced-0`). */ level: string; /** Add-on name (`--name`). */ name?: string; /** Private/Shield network variant; selects the `advanced[-private|-shield]` plan. */ network?: 'private' | 'shield'; /** Postgres version to provision. */ version?: string; }; export type ForkBody = { /** Attachment name (`--as`). */ as?: string; /** Extra provision options (parsed CLI `--provision-option` pairs). Merged last. */ config?: Record; /** Confirmation value for a `confirmation_required` retry. */ confirm?: string; /** * Leader compute level. When omitted, defaults to the source database's * current leader pool level. */ level?: string; /** Add-on name (`--name`). */ name?: string; /** * When set, provisions a point-in-time rollback instead of a live fork. A * `Date` is formatted to the platform's UTC `YYYY-MM-DDTHH:MM:SS`; a string * is passed through verbatim (matching the CLI's `--rollback-to`). */ recoveryTime?: Date | string; }; export type ProvisionAdvancedOptions = Pick & { /** * Fires once the leader add-on create request returns, before the wait * poll begins (only when `wait` is set), letting callers switch to a * "waiting for provisioning" display. */ onProvisioning?: (addon: AddOn) => Promise | void; /** Poll `wait_status` until the leader is ready before returning. */ wait?: boolean; }; export type ForkOptions = ProvisionAdvancedOptions & { /** * Fires once the source database is resolved and tier-checked, before the * fork create request is sent, letting callers defer a spinner until the * tier check passes and label it with the resolved source add-on rather than * the raw identity (mirrors `waitForReady`'s `onResolved`). An abort during * the hook prevents the create. */ onResolved?: (source: ResolvedAddOn) => Promise | void; }; export type ProvisionAdvancedResult = { /** * The newly-created leader add-on. Always present: the leader is billed the * moment creation succeeds, so it is reported even when a later step * (`wait`/follower pool) fails, letting callers surface what was provisioned * instead of retrying and provisioning a second leader. */ addon: AddOn; /** The follower pool, when `followers` was provided and its creation succeeded. */ pool?: PostgresPoolCreateResult; /** * The error thrown while creating the follower pool, when `followers` was * provided and creation failed. The leader (`addon`) still provisioned. */ poolError?: unknown; /** * The error thrown while waiting for the leader to become ready, when `wait` * was set and the wait failed (timeout, abort, 404-budget exhaustion, or a * transient API error). The leader (`addon`) still provisioned; the follower * pool is not attempted in this case. */ waitError?: unknown; /** The terminal wait status, when `wait` was set and the wait succeeded. */ waitStatus?: PostgresWaitStatusResult; }; export type ForkResult = { /** * The newly-created fork/rollback add-on. Always present once creation * succeeds, even if the subsequent `wait` fails (see * {@link ProvisionAdvancedResult.addon}). */ addon: AddOn; /** The resolved source database the fork was created from. */ source: ResolvedAddOn; /** * The error thrown while waiting for the fork to become ready, when `wait` * was set and the wait failed. The fork (`addon`) still provisioned. */ waitError?: unknown; /** The terminal wait status, when `wait` was set and the wait succeeded. */ waitStatus?: PostgresWaitStatusResult; }; /** * Resolves a Postgres database by attachment identity and polls its * `wait_status` until it reports ready. `waiting: true` covers any in-progress * operation (provisioning, migration, or update), not just initial provision. * * Throws `NotAdvancedDatabaseError` (carrying the resolved add-on) if the * database isn't an Advanced-tier database. */ export declare function waitForReady(ctx: Pick, appIdentity: string, addonIdentity?: string, options?: WaitForReadyOptions): Promise; /** * Provisions a new Advanced-tier Postgres leader (and, when `followers` is * given, a follower pool), replacing the CLI's `createAddon` + `createPool` * sequence. * * A `confirmation_required` response surfaces as `AddonConfirmationRequiredError` * — catch it, gather a confirmation value, and retry with `body.confirm` set * (the CLI retries with `confirm = app`). When `wait` is set, polls the data * `wait_status` endpoint (not the platform add-on state) until the leader is * ready; the follower pool is then created against the ready leader, matching * the CLI's ordering. * * **Partial failure.** Once the leader is created it is billed, so failures * after creation are not thrown — they are reported on the result so the caller * never loses track of what it provisioned. A failed `wait` sets `waitError` * (and the follower pool is not attempted); a failed follower-pool create sets * `poolError`. `addon` is always present on a returned result. A failure of the * leader create itself still throws (nothing was provisioned). The wait polls * the data `wait_status` endpoint rather than the platform add-on state, so it * is bounded by a default `timeoutMs` (see {@link WaitForReadyOptions}) as a * backstop against a platform-side provisioning failure that never surfaces on * `wait_status`; pass a larger `timeoutMs` for a longer wait. */ export declare function provisionAdvanced(ctx: Pick, appIdentity: string, body: ProvisionAdvancedBody, options?: ProvisionAdvancedOptions): Promise; /** * Forks (or, when `recoveryTime` is set, rolls back) an existing Advanced-tier * Postgres database into a new add-on on `appIdentity`. * * `sourceIdentity` is both resolved (to tier-check, default the level, and * pick the plan) and passed verbatim into the `fork`/`rollback` config value, * matching the CLI, which forks against the raw user-supplied identity. The * new add-on inherits the source's plan. * * Throws `NotAdvancedDatabaseError` (carrying the resolved source) if the * source isn't an Advanced-tier database. `onResolved` fires after a * successful tier check and before the create request. Confirmation and wait * semantics match `provisionAdvanced`. */ export declare function fork(ctx: Pick, appIdentity: string, sourceIdentity: string, body?: ForkBody, options?: ForkOptions): Promise; export declare const postgresExtensions: import("../../core/extend-resource.js").ResourceExtension<"data", "postgres", { fork: (appIdentity: string, sourceIdentity: string, body?: ForkBody, options?: ForkOptions) => Promise; provisionAdvanced: (appIdentity: string, body: ProvisionAdvancedBody, options?: ProvisionAdvancedOptions) => Promise; runUpgrade: (appIdentity: string, addonIdentity?: string, body?: PostgresRunUpgradeOpts, options?: RunUpgradeOptions) => Promise; waitForReady: (appIdentity: string, addonIdentity?: string, options?: WaitForReadyOptions) => Promise; }>;