import { type MigrationResult, type MigrationStatus, type SchemaMigration } from '../utils/schema-migrations.js'; import { type PostgresLikeClient } from './client.js'; export { type AppliedMigration, type MigrationResult, type MigrationStatus, migrationChecksum, type SchemaMigration, SchemaMigrationError, } from '../utils/schema-migrations.js'; /** Options for applying or inspecting Postgres migrations. */ export interface PostgresMigrateOptions { /** Plans without writing anything, not even the table that records migrations. */ dryRun?: boolean; /** The table that records applied migrations, optionally schema-qualified. Defaults to `nexus_schema_migrations`. */ table?: string; /** * Runs one migration's statements, and the row recording it, in one transaction on one connection. * Without it, statements run one at a time and the record is written last: every bundled statement * is idempotent, so an interrupted migration runs again on the next call. Pass it for a pool, where * `BEGIN` and `COMMIT` would otherwise reach different connections: * * ```ts * transaction: async (run) => { * const connection = await pool.connect(); * try { * await connection.query('BEGIN'); * const result = await run(connection); * await connection.query('COMMIT'); * return result; * } catch (error) { * await connection.query('ROLLBACK'); * throw error; * } finally { * connection.release(); * } * } * ``` * * PGlite needs only `transaction: (run) => db.transaction(run)`. */ transaction?: (run: (client: PostgresLikeClient) => Promise) => Promise; /** * How long one migrator holds the lock before another may take it over, renewed before each * migration. Defaults to 10 minutes, longer than any bundled migration takes. */ lockTtlMs?: number; /** How long to wait for another migrator to finish before giving up. Defaults to 2 minutes. */ lockTimeoutMs?: number; } /** * Where a Postgres database stands against a list of migrations. Reads only: on a database that has * never been migrated, everything is pending. */ export declare function postgresMigrationStatus(client: PostgresLikeClient, migrations: readonly SchemaMigration[], options?: Pick): Promise; /** * Applies the pending migrations in order, under a lock, recording each with a checksum. * * The lock is a row with a lease rather than a session advisory lock, so it holds through a * connection pool and serverless drivers alike: a second migrator waits, and one that died is taken * over once its lease lapses. A migration whose statements changed after it ran is refused before * anything is written. Migrations a newer release recorded are left alone, so an older worker * starting mid-rollout does nothing. */ export declare function applyPostgresMigrations(client: PostgresLikeClient, migrations: readonly SchemaMigration[], options?: PostgresMigrateOptions): Promise; /** The statements that create the migrations table and its lock, which `migrate()` runs first. */ export declare function migrationsTableStatements(table?: string): string[];