import postgres from 'postgres'; import type { Manifold } from '../core/pipework.js'; export interface ReapResult { readonly droppedDatabases: readonly string[]; /** * Databases inside this project's prefix that the reaper did NOT create and so * will not drop. Reported rather than dropped: sharing a prefix is not evidence * of ownership, and a name pipework never wrote belongs to somebody else (#391). */ readonly skippedDatabases: readonly string[]; } /** * Advisory-lock key identifying a test run. A live run holds this lock on a * dedicated connection for its entire lifetime; Postgres releases it * automatically when that connection ends by any means (clean exit, crash, * SIGKILL, reboot). The reaper reads "lock is free" as "owning run is dead". */ export declare function runLockKey(nonce: string): bigint; export declare function templateUseKey(fingerprint: string): bigint; export declare function templateBuildKey(fingerprint: string): bigint; /** Admin (`/postgres`) connection URL for a database URL. */ export declare function getAdminUrl(databaseUrl: string): string; /** * Drop test databases left behind by runs that never reached teardown * (Ctrl-C, timeout, crash). A database is reaped only when ALL THREE hold: * * - the reaper created it — its name carries the 12-hex run nonce every name * `testDbName` writes. Sharing the project prefix is not evidence of * ownership: a cluster carrying `_test_` control databases * lost all of them at once to a prefix-only sweep (#391). Anything else in * the prefix is reported in `skippedDatabases` and left alone; * - its run's advisory lock is free — the owning run's process is gone; and * - `numbackends = 0` — no connections remain, so reaping cannot pull a * database out from under workers orphaned by a SIGKILL'd parent. * * All three only ever make the reaper more conservative, so it can never drop a * database belonging to a live or still-provisioning run, or to anyone else. */ export declare function reapOrphanTestDatabases(admin: postgres.Sql, liveTemplates?: ReadonlySet): Promise; /** * Reap orphan test databases across every Postgres server referenced by the * manifold's database config. Used by `pipework test --reap`. */ export declare function reapConfiguredTestDatabases(instance: Manifold): Promise; //# sourceMappingURL=reap.d.ts.map