import type { PostgresInfoResult, PostgresMigrationCreateOpts, PostgresMigrationCreateResult, PostgresMigrationInfoResult } from '@heroku/types/data'; import type { ResourceCtx } from '../../core/extend-resource.js'; import type { AddOnAttachmentWithInclusions } from '../platform/add-on-attachment/resolve.js'; /** * A database migration record, as returned by `find`, `startWhenReady`, and * `abortBeforeRun`. The create/prepare response * (`PostgresMigrationCreateResult`) is structurally identical today — same * fields, same closed `status` union — but keeps its own generated type rather * than sharing this alias. */ export type Migration = PostgresMigrationInfoResult; /** The closed migration-status union, re-derived so callers don't restate it. */ export type MigrationStatus = Migration['status']; /** Request body for configuring a migration (the generated create opts). */ export type MigrationCreateBody = PostgresMigrationCreateOpts; export type MigrationOptions = { signal?: AbortSignal; }; /** * The reason a migration create request was rejected client-side. A * single-member discriminated union today; new guards add members here so * callers keep exhaustive handling. Server-side validation rejections are not * yet mapped onto this type — they surface as the raw API error. */ export type MigrationInvalidReason = 'source_equals_target'; /** * A classic Postgres database eligible to be migrated *from*, with the names * it's attached under on the app. */ export type MigrationSource = AddOnAttachmentWithInclusions['addon'] & { attachmentNames: string[]; }; /** * An Advanced Postgres database eligible to be migrated *to*, with its * attachment names, its current `info` (for availability gating), and any * migration currently targeting it. `info`/`migration` are absent when the * database's `/info` or `/migrations` endpoint 404s (not yet a target). */ export type MigrationTarget = AddOnAttachmentWithInclusions['addon'] & { attachmentNames: string[]; info?: PostgresInfoResult; migration?: Migration; }; export type MigrationContext = { /** All migration records currently configured on the app's Advanced databases. */ migrations: Migration[]; /** Classic (non-Essential) databases that can be migration sources. */ sources: MigrationSource[]; /** Advanced databases that can be migration targets. */ targets: MigrationTarget[]; }; /** * Thrown by `create` when the migration inputs are invalid before any request * fires. Carries a machine `reason` so callers can branch without string * matching. */ export declare class MigrationInvalidError extends Error { readonly reason: MigrationInvalidReason; readonly id = "migration_invalid"; constructor(reason: MigrationInvalidReason, message: string); get body(): { id: string; message: string; reason: "source_equals_target"; }; } /** * Thrown by `run` when the migration isn't in a startable state. Carries the * migration (and thus its `status`) so callers can report the drift without * re-fetching. */ export declare class MigrationNotRunnableError extends Error { readonly migration: Migration; readonly id = "migration_not_runnable"; constructor(migration: Migration); get body(): { id: string; message: string; status: "completed" | "failed" | "unknown" | "creating_target" | "preparing" | "migrating" | "cancelled" | "ready" | "promoting"; }; /** * The migration's status. Named `migrationStatus` (not `status`) to avoid * shadowing the HTTP-status convention other `Error` subclasses in the SDK * carry. */ get migrationStatus(): MigrationStatus; } /** * Thrown by `cancel` when the migration isn't in a cancellable state. Carries * the migration (and thus its `status`). */ export declare class MigrationNotCancellableError extends Error { readonly migration: Migration; readonly id = "migration_not_cancellable"; constructor(migration: Migration); get body(): { id: string; message: string; status: "completed" | "failed" | "unknown" | "creating_target" | "preparing" | "migrating" | "cancelled" | "ready" | "promoting"; }; /** * The migration's status. Named `migrationStatus` (not `status`) to avoid * shadowing the HTTP-status convention other `Error` subclasses in the SDK * carry. */ get migrationStatus(): MigrationStatus; } /** * Whether a migration can be started. Only `ready` migrations are runnable, * matching the CLI's menu gate. The exhaustive `switch` makes a newly * generated status a compile error until its policy is decided here, rather * than silently defaulting to runnable or not. */ export declare function isRunnable(status: MigrationStatus): boolean; /** * Whether a migration can be canceled. Only `ready` migrations are * cancellable, matching the CLI's menu gate. Exhaustive for the same reason as * {@link isRunnable}. */ export declare function isCancellable(status: MigrationStatus): boolean; /** * Fetches the migration currently targeting `targetAddonId`. * * The data API's migration endpoint is a single-object `GET` (not a list); * when no migration exists it 404s, which this surfaces as `undefined` rather * than throwing, so callers can treat "no migration" as a normal state. */ export declare function info(ctx: Pick, targetAddonId: string, options?: MigrationOptions): Promise; /** * Configures a new migration *to* `targetAddonId` *from* the database named in * `body.source_id`. * * The URL identifies the **target**; the body's `source_id` identifies the * **source** — both are add-on ids, so the two are easy to swap. A * client-side guard rejects a source that equals the target before any request * fires. */ export declare function create(ctx: Pick, targetAddonId: string, body: MigrationCreateBody, options?: MigrationOptions): Promise; /** * Starts the migration targeting `targetAddonId`. * * Fetches the migration first and gates on its status — a defensive backstop * against state drift between listing and action: throws * `MigrationNotRunnableError` (carrying the migration) if it's no longer * `ready`, and lets a `NotFoundError` propagate if the migration is already * gone. Once the run POST succeeds, returns the migration's post-action state * via a best-effort re-fetch (see {@link refetchAfterAction}); never throws * after the action has fired. */ export declare function run(ctx: Pick, targetAddonId: string, options?: MigrationOptions): Promise; /** * Cancels the migration targeting `targetAddonId`. * * Gates on status like {@link run}: throws `MigrationNotCancellableError` * (carrying the migration) if it's not `ready`, and lets a `NotFoundError` * propagate if the migration is already gone. Once the cancel POST succeeds, * returns the migration's post-action state via a best-effort re-fetch (see * {@link refetchAfterAction}); never throws after the action has fired. */ export declare function cancel(ctx: Pick, targetAddonId: string, options?: MigrationOptions): Promise; /** * Lists everything the migration UI needs for an app in one pass: the classic * databases that can be sources, the Advanced databases that can be targets * (each with its `info` and any migration targeting it), and the flat list of * configured migrations. * * Replaces the CLI's `getAppDatabases` + `getMigrationTargetsAndInfo`: resolves * the app's add-on attachments (with `addon:plan,config_vars` inclusions so * plans are present for tier classification), keeps only Postgres databases * the app owns, dedupes to unique add-ons with their attachment names, then * fans out `/migrations` and `/info` per Advanced database. A per-database 404 * is tolerated (that database simply isn't a migration target yet); the first * non-404 rejection is rethrown. */ export declare function listMigrationContext(ctx: Pick, appIdentity: string, options?: MigrationOptions): Promise; export declare const postgresMigrationExtensions: import("../../core/extend-resource.js").ResourceExtension<"data", "postgresMigration", { abortBeforeRun: (targetAddonId: string, options?: MigrationOptions) => Promise; find: (targetAddonId: string, options?: MigrationOptions) => Promise; listMigrationContext: (appIdentity: string, options?: MigrationOptions) => Promise; prepare: (targetAddonId: string, body: MigrationCreateBody, options?: MigrationOptions) => Promise; startWhenReady: (targetAddonId: string, options?: MigrationOptions) => Promise; }>;