import type { AddOnAttachment, Release } from '@heroku/types/3.sdk'; import type { DatabaseInfoResult, DatabaseResetResult as DatabaseResetResponse, DatabaseUnfollowResult as DatabaseUnfollowResponse, DatabaseWaitStatusResult } from '@heroku/types/data'; import type { ResourceCtx } from '../../core/extend-resource.js'; import type { ResolvedPgDatabase } from './internal/resolve-pg-database.js'; export type DatabaseCommandInfo = Omit & { following?: null | string; leader?: unknown; }; export declare class DatabaseNotReadyError extends Error { readonly status: DatabaseWaitStatusResult; constructor(status: DatabaseWaitStatusResult); } export declare class DatabaseAlreadyPromotedError extends Error { readonly appIdentity: string; readonly addon: ResolvedPgDatabase; readonly attachment: AddOnAttachment; constructor(appIdentity: string, addon: ResolvedPgDatabase, attachment: AddOnAttachment); } export declare class DatabaseReleasePhaseError extends Error { readonly appIdentity: string; readonly attachRelease?: Release | undefined; readonly detachRelease?: Release | undefined; constructor(appIdentity: string, attachRelease?: Release | undefined, detachRelease?: Release | undefined); } export declare class DatabasePromotionError extends Error { readonly result: PromoteDatabasePartialResult; constructor(result: PromoteDatabasePartialResult, cause: unknown); } export declare class DatabaseNotFollowerError extends Error { readonly addon: ResolvedPgDatabase; constructor(addon: ResolvedPgDatabase); } export type PromoteDatabasePreview = { addon: ResolvedPgDatabase; appIdentity: string; attachment: AddOnAttachment; currentAttachment?: AddOnAttachment; existingAlias?: AddOnAttachment; }; export type PromoteDatabaseOptions = { /** Attachment name to create for the promoted database; defaults to DATABASE. */ as?: string; /** Runs after resolution, alias inspection, and readiness checks, before mutation. */ beforePromote?: (preview: PromoteDatabasePreview) => Promise | void; /** Skip the legacy database readiness check. */ force?: boolean; /** Runs after the current DATABASE backup alias is created, if needed. */ onBackupAttachment?: (attachment: AddOnAttachment) => Promise | void; /** * Receives best-effort progress updates. Synchronous throws and rejected * promises are ignored so an observer cannot change the promotion outcome. */ onProgress?: (event: PromoteDatabaseProgressEvent) => Promise | void; /** Delay between release-phase status polls. Defaults to 5 seconds. */ releasePhasePollIntervalMs?: number; /** Maximum time to wait for release-phase completion. Defaults to 15 minutes. */ releasePhaseTimeoutMs?: number; signal?: AbortSignal; }; export type PromoteDatabaseProgressEvent = { attach?: Release; detach?: Release; stage: 'completed' | 'poll' | 'started'; status: PromoteDatabaseReleasePhaseStatus; type: 'release-phase'; } | { attachment?: AddOnAttachment; stage: 'backup' | 'promotion'; status: 'started' | 'succeeded' | 'unknown'; type: 'attachment'; } | { attachment?: AddOnAttachment; stage: 'reattachment'; status: 'started' | 'succeeded' | 'unknown'; type: 'pooler-reattachment'; } | { database: DatabaseCommandInfo; stage: 'resolved'; type: 'database'; }; export type PromoteDatabaseReleasePhaseStatus = 'failed' | 'not_required' | 'pending' | 'started' | 'succeeded' | 'timed_out' | 'unknown'; export type PromoteDatabasePartialResult = { addon: ResolvedPgDatabase; attachment?: AddOnAttachment; backupAttachment?: AddOnAttachment; database?: DatabaseCommandInfo; mutationStatus: { attachment: PromotionMutationStatus; backupAttachment: PromotionMutationStatus; poolerAttachment: PromotionMutationStatus; }; poolerAttachment?: AddOnAttachment; releasePhase?: { attach?: Release; detach?: Release; status: 'failed' | 'succeeded' | 'timed_out' | 'unknown'; }; }; export type PromoteDatabaseResult = PromoteDatabasePartialResult & { attachment: AddOnAttachment; }; export type PromotionMutationStatus = { attempted: boolean; status: 'created' | 'not_attempted' | 'unknown'; }; export type UnfollowDatabasePreview = { addon: ResolvedPgDatabase; appIdentity: string; attachment: AddOnAttachment; database: DatabaseCommandInfo; following: string; origin: UnfollowDatabaseOrigin; }; export type UnfollowDatabaseOrigin = { defaultPort: string; hostname: string; pathname: string; port: string; protocol: string; type: 'url'; } | { name: string; rawName: string; type: 'config_var'; }; export type UnfollowDatabaseOptions = { /** Runs after resolving follower/origin details and before the unfollow request. */ beforeUnfollow?: (preview: UnfollowDatabasePreview) => Promise | void; signal?: AbortSignal; }; export type UnfollowDatabaseResult = { addon: ResolvedPgDatabase; database: DatabaseCommandInfo; following: string; origin: UnfollowDatabaseOrigin; result: DatabaseUnfollowResponse; }; export type ResetDatabaseOptions = { /** * Runs after the database is resolved and before the reset request. A throw * (or abort) from the callback prevents the destructive request. */ beforeReset?: (preview: { addon: ResolvedPgDatabase; appIdentity: string; }) => Promise | void; /** Comma-separated extension names, or an already split list. */ extensions?: string | string[]; signal?: AbortSignal; }; export type ResetDatabaseResult = { addon: ResolvedPgDatabase; result: DatabaseResetResponse; }; /** Resolve a database, protect the existing alias, and promote it to DATABASE. */ export declare function promoteDatabase(ctx: Pick, appIdentity: string, databaseIdentity?: string, options?: PromoteDatabaseOptions): Promise; /** Resolve a follower and its displayed origin, then stop replication. */ export declare function unfollowDatabase(ctx: Pick, appIdentity: string, databaseIdentity?: string, options?: UnfollowDatabaseOptions): Promise; /** Resolve a database and reset it with the requested public-schema extensions. */ export declare function resetDatabase(ctx: Pick, appIdentity: string, databaseIdentity?: string, options?: ResetDatabaseOptions): Promise; export declare const databaseCommandExtensions: import("../../core/extend-resource.js").ResourceExtension<"data", "database", { /** Canonical app-scoped name; replaces the former `promote` extension method. */ promoteForApp: (appIdentity: string, databaseIdentity?: string, options?: PromoteDatabaseOptions) => Promise; resetForApp: (appIdentity: string, databaseIdentity?: string, options?: ResetDatabaseOptions) => Promise; unfollowForApp: (appIdentity: string, databaseIdentity?: string, options?: UnfollowDatabaseOptions) => Promise; }>;