import type { ConnectionOptions } from 'node:tls'; import type { CreateIndexOptions, RetentionConfig } from '@mastra/core/storage'; import type { ClientConfig, Pool, PoolConfig } from 'pg'; /** * Base configuration options shared across PostgreSQL configs. */ export interface PostgresBaseConfig { id: string; schemaName?: string; /** Optional read-replica pool. Falls back to the writer pool when omitted. */ readPool?: Pool; /** * When true, automatic initialization (table creation/migrations) is disabled. * This is useful for CI/CD pipelines where you want to: * 1. Run migrations explicitly during deployment (not at runtime) * 2. Use different credentials for schema changes vs runtime operations * * When disableInit is true: * - The storage will not automatically create/alter tables on first use * - You must call `storage.init()` explicitly in your CI/CD scripts * * @example * // In CI/CD script: * const storage = new PostgresStore({ ...config, disableInit: false }); * await storage.init(); // Explicitly run migrations * * // In runtime application: * const storage = new PostgresStore({ ...config, disableInit: true }); * // No auto-init, tables must already exist */ disableInit?: boolean; /** * When true, default indexes will not be created during initialization. * This is useful when: * 1. You want to manage indexes separately or use custom indexes only * 2. Default indexes don't match your query patterns * 3. You want to reduce initialization time in development * * @default false */ skipDefaultIndexes?: boolean; /** * Custom indexes to create during initialization. * These indexes are created in addition to default indexes (unless skipDefaultIndexes is true). * * Each index must specify which table it belongs to. The store will route each index * to the appropriate domain based on the table name. * * @example * ```typescript * const store = new PostgresStore({ * connectionString: '...', * indexes: [ * { name: 'my_threads_type_idx', table: 'mastra_threads', columns: ['metadata->>\'type\''] }, * { name: 'my_messages_status_idx', table: 'mastra_messages', columns: ['metadata->>\'status\''] }, * ], * }); * ``` */ indexes?: CreateIndexOptions[]; /** * Opt-in, table-granular, age-based retention policies. Declare per-table * `maxAge` per domain (e.g. `{ memory: { messages: { maxAge: '30d' } } }`); * unset tables are kept forever. Wire `storage.prune()` to your own cron to * apply them. See {@link RetentionConfig}. */ retention?: RetentionConfig; } /** * Connection string configuration. */ export interface ConnectionStringConfig extends PostgresBaseConfig { connectionString: string; ssl?: boolean | ConnectionOptions; max?: number; idleTimeoutMillis?: number; } /** * Host-based configuration. */ export interface HostConfig extends PostgresBaseConfig { host: string; port: number; database: string; user: string; password: string; ssl?: boolean | ConnectionOptions; max?: number; idleTimeoutMillis?: number; } /** * Pre-configured pg.Pool configuration. */ export interface PoolInstanceConfig extends PostgresBaseConfig { /** * Pre-configured writer pg.Pool instance. * Use this for direct control over the connection pool, or for * integration with libraries that expect a pg.Pool. * * @example * ```typescript * import { Pool } from 'pg'; * * const pool = new Pool({ connectionString: '...' }); * const store = new PostgresStore({ id: 'my-store', pool }); * * // Use store.pool for other libraries that need a pg.Pool * ``` */ pool: Pool; writePool?: never; } /** Pre-configured writer pool using the explicit read/write naming. */ export interface WritePoolInstanceConfig extends PostgresBaseConfig { writePool: Pool; pool?: never; } /** * PostgreSQL configuration for PostgresStore. * * Accepts either: * - A pre-configured pg.Pool: `{ id, pool, schemaName? }` * - Connection string: `{ id, connectionString, ... }` * - Host/port config: `{ id, host, port, database, user, password, ... }` * - Cloud SQL connector config: `{ id, stream, ... }` (via pg.ClientConfig) */ export type PostgresStoreConfig = PoolInstanceConfig | WritePoolInstanceConfig | ConnectionStringConfig | HostConfig | (PostgresBaseConfig & ClientConfig); /** * PostgreSQL configuration for PgVector (uses pg with ConnectionOptions) */ export type PgVectorConfig = (ConnectionStringConfig | HostConfig | (PostgresBaseConfig & ClientConfig)) & { pgPoolOptions?: Omit; }; /** * Type guard for pre-configured pg.Pool config */ export declare const isPoolConfig: (cfg: PostgresStoreConfig) => cfg is PoolInstanceConfig; /** Type guard for an explicitly named pre-configured writer pool. */ export declare const isWritePoolConfig: (cfg: PostgresStoreConfig) => cfg is WritePoolInstanceConfig; /** * Type guard for connection string config */ export declare const isConnectionStringConfig: (cfg: PostgresStoreConfig) => cfg is ConnectionStringConfig; /** * Type guard for host-based config */ export declare const isHostConfig: (cfg: PostgresStoreConfig) => cfg is HostConfig; /** * Type guard for Cloud SQL connector config */ export declare const isCloudSqlConfig: (cfg: PostgresStoreConfig) => cfg is PostgresBaseConfig & ClientConfig; /** * Validate PostgresStore configuration. */ export declare const validateConfig: (name: string, config: PostgresStoreConfig) => void; //# sourceMappingURL=config.d.ts.map