import { type PlanetScaleProps } from "./api.ts"; import type { Branch } from "./branch.ts"; import type { Database } from "./database.ts"; /** * Configuration for the pg_cron extension. * Schedules and runs PostgreSQL commands inside the database. */ export interface PgCronConfig { /** * The database in which pg_cron metadata is kept. * @default "postgres" */ databaseName?: string; /** * Whether to launch active jobs when pg_cron starts. * @default "on" */ launchActiveJobs?: "on" | "off"; /** * Minimum message level for pg_cron log messages. * @default "warning" */ logMinMessages?: "error" | "warning" | "notice" | "info" | "log" | "debug"; /** * Whether to log each job run into the job_run_details table. * @default "on" */ logRun?: "on" | "off"; /** * Whether to log the SQL statement of each job. * @default "on" */ logStatement?: "on" | "off"; /** * Maximum number of concurrently running jobs. * @default 1 */ maxRunningJobs?: number; } /** * Configuration for the pg_duckdb extension. * Embeds DuckDB inside PostgreSQL for analytical queries. */ export interface PgDuckdbConfig { /** * The PostgreSQL role used by DuckDB. * @default "pscale_superuser" */ postgresRole?: string; /** * Memory limit for DuckDB. 0 means unlimited. * @default "0" */ memoryLimit?: string; } /** * Configuration for the pg_hint_plan extension. * Controls query execution plans using hints in SQL comments. */ export interface PgHintPlanConfig { /** * Whether to enable hint processing. * @default "on" */ enableHint?: "on" | "off"; /** * Whether to enable the hint table feature. * @default "off" */ enableHintTable?: "on" | "off"; /** * Message level for hint parsing messages. * @default "info" */ parseMessages?: "error" | "warning" | "notice" | "info" | "log" | "debug"; /** * Controls debug output of query plans. * @default "off" */ debugPrint?: "off" | "on" | "detailed" | "verbose"; /** * Message level for debug output. * @default "info" */ messageLevel?: "error" | "warning" | "notice" | "info" | "log" | "debug"; } /** * Configuration for the pg_partman background worker extension. * Automates partition management for time-based and serial-based partitioning. */ export interface PgPartmanBgwConfig { /** * How often (in seconds) the background worker runs maintenance. * @default 3600 */ interval?: number; /** * The database to connect to for maintenance. * @default "postgres" */ dbname?: string; /** * The role to use when connecting. * @default "postgres" */ role?: string; /** * Whether to run ANALYZE on partitions after maintenance. * @default "off" */ analyze?: "on" | "off"; /** * Whether to use pg_jobmon for logging. * @default "on" */ jobmon?: "on" | "off"; } /** * Configuration for the pg_squeeze extension. * Removes dead tuples from tables with minimal locking. */ export interface PgSqueezeConfig { /** * Maximum time (in milliseconds) to hold an exclusive lock during processing. 0 means no limit. * @default 0 */ maxXlockTime?: number; /** * Databases in which the squeeze worker auto-starts, comma-separated. * @default "postgres" */ workerAutostart?: string; /** * Number of squeeze workers per database. * @default 1 */ workersPerDatabase?: number; } /** * Configuration for the pg_stat_statements extension. * Tracks planning and execution statistics of all SQL statements. */ export interface PgStatStatementsConfig { /** * Maximum number of statements tracked. * @default 5000 */ max?: number; /** * Which statements to track. * @default "top" */ track?: "top" | "all"; /** * Whether to track utility commands. * @default "on" */ trackUtility?: "on" | "off"; /** * Whether to track planning statistics. * @default "off" */ trackPlanning?: "on" | "off"; /** * Whether to save statistics across server restarts. * @default "on" */ save?: "on" | "off"; } /** * Configuration for the timescaledb extension. * Provides time-series data support for PostgreSQL. */ export interface TimescaledbConfig { /** * Log level for the background worker. * @default "warning" */ bgwLogLevel?: "error" | "warning" | "notice" | "info" | "log" | "debug"; /** * Enable chunk append optimization. * @default "on" */ enableChunkAppend?: "on" | "off"; /** * Enable chunk skipping optimization. * @default "off" */ enableChunkSkipping?: "on" | "off"; /** * Enable constraint-aware append optimization. * @default "on" */ enableConstraintAwareAppend?: "on" | "off"; /** * Enable constraint exclusion optimization. * @default "on" */ enableConstraintExclusion?: "on" | "off"; /** * Enable custom hash aggregate optimization. * @default "off" */ enableCustomHashagg?: "on" | "off"; /** * Enable deprecation warnings. * @default "on" */ enableDeprecationWarnings?: "on" | "off"; /** * Enable event triggers. * @default "off" */ enableEventTriggers?: "on" | "off"; /** * Enable foreign key propagation. * @default "on" */ enableForeignKeyPropagation?: "on" | "off"; /** * Enable logging of job execution. * @default "off" */ enableJobExecutionLogging?: "on" | "off"; /** * Enable now() constification. * @default "on" */ enableNowConstify?: "on" | "off"; /** * Enable query optimizations. * @default "on" */ enableOptimizations?: "on" | "off"; /** * Enable ordered append optimization. * @default "on" */ enableOrderedAppend?: "on" | "off"; /** * Enable parallel chunk append optimization. * @default "on" */ enableParallelChunkAppend?: "on" | "off"; /** * Enable qual propagation optimization. * @default "on" */ enableQualPropagation?: "on" | "off"; /** * Enable runtime exclusion optimization. * @default "on" */ enableRuntimeExclusion?: "on" | "off"; /** * Enable tiered reads. * @default "on" */ enableTieredReads?: "on" | "off"; /** * Enable TSS callbacks. * @default "on" */ enableTssCallbacks?: "on" | "off"; /** * Maximum number of cached chunks per hypertable. * @default 1024 */ maxCachedChunksPerHypertable?: number; /** * Maximum number of open chunks per insert. * @default 1024 */ maxOpenChunksPerInsert?: number; /** * Whether the database is being restored from a backup. * @default "off" */ restoring?: "on" | "off"; } /** * Configuration for the pgvector extension. * Provides vector similarity search for PostgreSQL. */ export interface PgvectorConfig { /** * Size of the dynamic candidate list for HNSW search. * @default 40 */ hnswEfSearch?: number; /** * Whether to enable iterative scan for HNSW indexes. * @default "off" */ hnswIterativeScan?: "off" | "relaxed_order" | "strict_order"; /** * Maximum number of tuples to scan with HNSW iterative scan. * @default 20000 */ hnswMaxScanTuples?: number; /** * Memory multiplier for HNSW scans. * @default 1 */ hnswScanMemMultiplier?: number; /** * Number of probes for IVFFlat index search. * @default 1 */ ivfflatProbes?: number; /** * Whether to enable iterative scan for IVFFlat indexes. * @default "off" */ ivfflatIterativeScan?: "off" | "relaxed_order" | "strict_order"; /** * Maximum number of probes for IVFFlat iterative scan. * @default 32768 */ ivfflatMaxProbes?: number; } /** * Configuration for the pginsights extension. * Provides query performance insights. */ export interface PgInsightsConfig { /** * Whether to collect raw (un-normalized) queries. * @default "off" */ rawQueries?: "on" | "off"; /** * Whether to normalize schema names in queries. * @default "off" */ normalizeSchemaNames?: "on" | "off"; } /** * PostgreSQL database extensions configuration. * * Each property represents an extension. If present (even as `{}`), the extension * is enabled with the given config (or defaults). If absent/undefined, the extension * is disabled. */ export interface DatabaseExtensions { /** * pg_cron - Job scheduler for PostgreSQL. * Schedules and runs PostgreSQL commands on a recurring basis. */ pgCron?: PgCronConfig; /** * pg_duckdb - Embedded DuckDB for analytical queries. */ pgDuckdb?: PgDuckdbConfig; /** * pg_hint_plan - Query plan hints. * Controls execution plans using hints in SQL comments. */ pgHintPlan?: PgHintPlanConfig; /** * pg_partman (background worker) - Partition management automation. */ pgPartmanBgw?: PgPartmanBgwConfig; /** * pg_squeeze - Dead tuple removal with minimal locking. */ pgSqueeze?: PgSqueezeConfig; /** * pg_stat_statements - Query execution statistics tracking. */ pgStatStatements?: PgStatStatementsConfig; /** * pg_strict - Stricter SQL behavior for PostgreSQL. * This extension has no configurable parameters. */ pgStrict?: Record; /** * timescaledb - Time-series data support. */ timescaledb?: TimescaledbConfig; /** * pgvector - Vector similarity search. */ vector?: PgvectorConfig; /** * pginsights - Query performance insights. */ pgInsights?: PgInsightsConfig; } /** * A single change within an extensions diff: add, remove, or update. * @internal */ export interface ExtensionDiffEntry { /** * The shared_preload_libraries name (e.g. "pg_cron", "vector"). */ library: string; /** * "add" = extension is being enabled, * "remove" = extension is being disabled, * "update" = extension params changed (stays enabled). */ action: "add" | "remove" | "update"; /** * The pgconf parameter key-value pairs to send for this extension. * Empty for "remove" actions. */ params: Record; } /** * Result of diffing two DatabaseExtensions objects. * @internal */ export interface ExtensionsDiff { /** * Individual changes per extension. */ changes: ExtensionDiffEntry[]; /** * True if there are any changes at all. */ hasChanges: boolean; } /** * Converts a DatabaseExtensions object into a map of library name -> pgconf params. * Only includes extensions that are present (enabled). * @internal */ export declare function extensionsToParamMappings(extensions: DatabaseExtensions): Map>; /** * Computes the diff between two extension configurations. * * @param current - The currently active extensions (or `undefined`/`{}` if none) * @param desired - The desired extensions configuration * @returns An ExtensionsDiff describing what needs to change * * @example * ```ts * const diff = diffExtensions( * { pgCron: { maxRunningJobs: 1 } }, * { pgCron: { maxRunningJobs: 5 }, vector: {} }, * ); * // diff.changes = [ * // { library: "pg_cron", action: "update", params: { "cron.max_running_jobs": "5" } }, * // { library: "vector", action: "add", params: {} }, * // ] * ``` */ export declare function diffExtensions(current: DatabaseExtensions | undefined, desired: DatabaseExtensions | undefined): ExtensionsDiff; /** * Options for updating database extensions. */ export interface UpdateExtensionsOptions extends PlanetScaleProps { /** * The organization name. * @default process.env.PLANETSCALE_ORGANIZATION */ organization?: string; /** * The database name or Database resource. */ database: string | Database; /** * The branch name or Branch resource. * @default "main" */ branch?: string | Branch; /** * The base URL of the PlanetScale API. * @default "https://api.planetscale.com/v1" */ baseUrl?: string; } /** * Updates the PostgreSQL extensions on a PlanetScale database branch. * * Uses the reverse-engineered two-phase change request API: * 1. **Queue** — submits a change request with the desired extension config * 2. **Apply** — triggers execution of the queued change * 3. **Poll** — waits for the change to complete * * @param desired - The desired extension configuration. Extensions present are enabled; * extensions absent are disabled. * @param options - Connection and targeting options. * * @example * ## Enable pgvector and pg_cron * * ```ts * await updateExtensions( * { * vector: { hnswEfSearch: 100 }, * pgCron: {}, * }, * { * organization: "my-org", * database: "my-db", * branch: "main", * }, * ); * ``` * * @example * ## Disable all user extensions * * ```ts * await updateExtensions({}, { * organization: "my-org", * database: "my-db", * }); * ``` */ export declare function updateExtensions(desired: DatabaseExtensions, options: UpdateExtensionsOptions): Promise; //# sourceMappingURL=database-extensions.d.ts.map