/** * Apply (or roll back) the Postgres schema migrations the library ships in * `migrations/`. The migrations are only needed by callers who use the * optional Postgres NOTIFY signal layer (`createSignalEmitter` / * `createSignalListener`); polling-only deployments do not need Postgres * and can skip this entirely. * * Schema namespacing: * * - The broker's Postgres state (the `topic_heads` table and the migration * tracking table) lives in a dedicated schema, default `streams`. Pass * `schemaName` to override — useful when `streams` is already taken by * the consumer's own application. * - The migration-tracking table is `.pgmigrations`, NOT the * `node-pg-migrate` default `public.pgmigrations`. That way the library's * migration history cannot collide with whatever migration tool the * consumer's own application uses — the tracking lives entirely inside * the broker's own schema. * * @see ../migrations/ for the SQL definitions. * @see docs/architecture.md §Postgres schema. */ /** Default schema for the broker's Postgres state. */ export declare const DEFAULT_SCHEMA_NAME = "streams"; /** * Options for {@link applyMigrations} and {@link rollbackMigrations}. * * Either `pool` (preferred) or `databaseUrl` must be provided. * * **Use `pool` when:** you're on managed identity / IAM (Azure Database for * PostgreSQL with AAD, AWS RDS IAM auth, etc.) or any token-refreshing * credential. Build the pool with `pg`'s `password: async () => token` * function pattern; the library borrows a client from the pool during * migration so it inherits the pool's auth + token-refresh behaviour. * * **Use `databaseUrl` when:** you have a static credential (local dev, * test environments, container secrets) — convenience only. Connection * strings cannot express the `password-as-function` shape, so this path * does NOT support managed-identity credentials whose token expires. */ export type MigrationOptions = { /** * Postgres connection string. Convenience for static credentials only — * not compatible with managed identity / AAD token refresh. */ databaseUrl?: string; /** * A `pg.Pool` instance — the library borrows one client from it via * `pool.connect()` and releases it back when the migration completes. * The caller retains ownership of the pool and is responsible for * `pool.end()`. This is the path that supports managed-identity * credentials. */ pool?: import('pg').Pool; /** * Schema in which to place the broker's Postgres state (`topic_heads` and * the migration-tracking table). Defaults to `streams`. Must match the * `schemaName` you pass to {@link applyMigrations} every time AND the * `schemaName` used at runtime by `createSignalEmitter` / * `createSignalListener` — the library does not infer this from the * database at runtime. * * Validated against the same identifier regex used for tenant / topic. */ schemaName?: string; /** * `node-pg-migrate` logger. Silent by default. */ logger?: { info: (msg: string) => void; warn: (msg: string) => void; error: (msg: string) => void; debug: (msg: string) => void; }; }; /** * Apply pending Postgres migrations for the broker's schema (default * `streams`). Idempotent — already-applied migrations are skipped via the * `.pgmigrations` tracking table. * * @example Managed identity (Azure AAD) * ```ts * import { Pool } from 'pg'; * import { DefaultAzureCredential } from '@azure/identity'; * import { applyMigrations } from '@makerx/blob-data-streamer'; * * const credential = new DefaultAzureCredential(); * const pool = new Pool({ * host: 'mydb.postgres.database.azure.com', * user: 'mydb-admin', * database: 'mydb', * password: async () => (await credential.getToken('https://ossrdbms-aad.database.windows.net')).token, * ssl: { rejectUnauthorized: true }, * }); * await applyMigrations({ pool }); * // ... now safe to use createSignalEmitter / createSignalListener. * await pool.end(); * ``` * * @example Static credentials (local dev / containers) * ```ts * await applyMigrations({ databaseUrl: process.env.DATABASE_URL }); * ``` * * @example Custom schema (avoid collision with an existing `streams` schema) * ```ts * await applyMigrations({ pool, schemaName: 'broker' }); * // Pass the same schemaName to createSignalEmitter / createSignalListener. * ``` */ export declare function applyMigrations(opts: MigrationOptions): Promise; /** * Roll back the most recently applied migration. Intended for development * and test cleanup; production use is rare. */ export declare function rollbackMigrations(opts: MigrationOptions): Promise; //# sourceMappingURL=migrations.d.ts.map