/** * Schema migration system for Signet * Detects and migrates between different memory database schemas */ export type SchemaType = "python" | "cli-v1" | "core" | "unknown"; export interface SchemaInfo { type: SchemaType; version: number; hasMemories: boolean; hasConversations: boolean; hasEmbeddings: boolean; hasFts: boolean; memoryCount: number; columns: string[]; } export interface MigrationResult { migrated: boolean; fromSchema: SchemaType; toSchema: SchemaType; memoriesMigrated: number; errors: string[]; } /** * Detect the current schema type by examining table structure */ export declare function detectSchema(db: { prepare(sql: string): { get(...args: unknown[]): Record | undefined; all(...args: unknown[]): Record[]; }; exec?(sql: string): void; }): SchemaInfo; /** * Ensure schema_migrations table has all required columns * Handles migration from old schema that was missing checksum column */ export declare function ensureMigrationsTableSchema(db: { exec(sql: string): void; prepare(sql: string): { all(...args: unknown[]): Record[]; }; }): void; /** * The unified schema that all migrations target */ export declare const UNIFIED_SCHEMA = "\n -- Schema version tracking\n CREATE TABLE IF NOT EXISTS schema_migrations (\n version INTEGER PRIMARY KEY,\n applied_at TEXT NOT NULL,\n checksum TEXT NOT NULL\n );\n\n -- Conversations table\n CREATE TABLE IF NOT EXISTS conversations (\n id TEXT PRIMARY KEY,\n session_id TEXT NOT NULL,\n harness TEXT NOT NULL,\n started_at TEXT NOT NULL,\n ended_at TEXT,\n summary TEXT,\n topics TEXT,\n decisions TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n updated_by TEXT NOT NULL,\n vector_clock TEXT NOT NULL DEFAULT '{}',\n version INTEGER DEFAULT 1,\n manual_override INTEGER DEFAULT 0\n );\n\n -- Unified memories table with all fields from all schemas\n CREATE TABLE IF NOT EXISTS memories (\n id TEXT PRIMARY KEY,\n type TEXT NOT NULL DEFAULT 'fact',\n category TEXT,\n content TEXT NOT NULL,\n confidence REAL DEFAULT 1.0,\n importance REAL DEFAULT 0.5,\n source_id TEXT,\n source_type TEXT,\n tags TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n updated_by TEXT NOT NULL,\n last_accessed TEXT,\n access_count INTEGER DEFAULT 0,\n vector_clock TEXT NOT NULL DEFAULT '{}',\n version INTEGER DEFAULT 1,\n manual_override INTEGER DEFAULT 0,\n pinned INTEGER DEFAULT 0\n );\n\n -- Embeddings table\n CREATE TABLE IF NOT EXISTS embeddings (\n id TEXT PRIMARY KEY,\n content_hash TEXT NOT NULL UNIQUE,\n vector BLOB NOT NULL,\n dimensions INTEGER NOT NULL,\n source_type TEXT NOT NULL,\n source_id TEXT NOT NULL,\n chunk_text TEXT NOT NULL,\n created_at TEXT NOT NULL\n );\n\n -- Indexes\n CREATE INDEX IF NOT EXISTS idx_conversations_session ON conversations(session_id);\n CREATE INDEX IF NOT EXISTS idx_conversations_harness ON conversations(harness);\n CREATE INDEX IF NOT EXISTS idx_memories_type ON memories(type);\n CREATE INDEX IF NOT EXISTS idx_memories_category ON memories(category);\n CREATE INDEX IF NOT EXISTS idx_memories_pinned ON memories(pinned);\n CREATE INDEX IF NOT EXISTS idx_memories_importance ON memories(importance DESC);\n CREATE INDEX IF NOT EXISTS idx_memories_created ON memories(created_at DESC);\n CREATE INDEX IF NOT EXISTS idx_embeddings_source ON embeddings(source_type, source_id);\n CREATE INDEX IF NOT EXISTS idx_embeddings_hash ON embeddings(content_hash);\n"; /** * Ensure database has the unified schema, migrating if necessary */ export declare function ensureUnifiedSchema(db: { exec(sql: string): void; prepare(sql: string): { run(...args: unknown[]): void; all(...args: unknown[]): Record[]; get(...args: unknown[]): Record | undefined; }; }): MigrationResult; //# sourceMappingURL=migration.d.ts.map