/** * SQLite schema migration module for the MCP token store. * * Applies versioned migrations to a better-sqlite3 database in a single * transaction. Safe to call on every daemon startup — skips migrations that * have already been applied. * * Also provides Go database migration: detectGoDatabase() and migrateFromGo() * locate and migrate legacy padua-mcp SQLite token databases to the new * tokens.db format. The wire format is byte-compatible between Go and TS. */ import Database from 'better-sqlite3'; import type { MigrationResult } from './types.js'; /** * Apply any outstanding schema migrations to the given database. * * Wraps all migration statements in a single transaction. If any statement * throws, the transaction is rolled back and no partial changes remain. * * @param db - An open better-sqlite3 database instance. * @returns MigrationResult indicating whether migrations were applied. * @throws StoreError(DB_WRITE_FAILED) if any database operation fails, * including introspection queries and migration statements. */ export declare function runMigrations(db: Database.Database): MigrationResult; /** * Result returned by migrateFromGo. * * Distinct from MigrationResult so that tokensCount is always present on * success and reason is always present on skip, giving callers a typed * discriminated union instead of a bag of optionals. */ export interface GoMigrationResult { /** Whether tokens were actually migrated. */ migrated: boolean; /** * Machine-readable skip reason. Only set when migrated is false. * 'no-legacy-db-found' — no Go database exists at any search path * 'wal-files-present' — WAL file exists; Go process may still hold a lock * 'decryption-failed' — provided key cannot decrypt the Go token data */ reason?: string; /** Number of token rows migrated. Set when migrated is true. */ tokensCount?: number; } export declare const LEGACY_DB_PATHS: readonly string[]; /** * Return the first path in searchPaths that resolves to an existing file, * or null when none exist. * * @param searchPaths - Ordered list of candidate paths. Defaults to LEGACY_DB_PATHS. */ export declare function detectGoDatabase(searchPaths?: string[]): string | null; /** * Migrate tokens from a legacy Go padua-mcp SQLite database to the new * encrypted tokens.db. * * Steps: * 1. Locate the Go database via detectGoDatabase. * 2. Abort when a WAL file is present (Go process may still be running). * 3. Open the Go database read-only and decrypt every row with the provided key. * 4. Write all rows into the target store using SqliteTokenStore. * 5. Rename the Go database to .bak so it is not migrated again. * * @param encryptionKey - 64-char hex AES-256 key (same key used by the Go app). * @param targetDbPath - Absolute path to the destination tokens.db file. * @param searchPaths - Override the default LEGACY_DB_PATHS (used in tests). */ export declare function migrateFromGo(encryptionKey: string, targetDbPath: string, searchPaths?: string[]): GoMigrationResult; //# sourceMappingURL=migrate.d.ts.map