/** * SQLite Database Schema for Agent World System * * Logger Category: storage.schema * Purpose: Schema utilities and PRAGMA configuration * * Features: * - PRAGMA configuration for performance and integrity * - Schema version tracking (PRAGMA user_version) * - Database statistics and integrity validation * - Index and trigger creation utilities * * Schema Design: * - worlds: Core world configuration and metadata * - agents: Agent configuration with LLM settings * - agent_memory: Current active conversation memory * - memory_archives: Archive session metadata with rich information * - archived_messages: Historical conversation content linked to archives * - archive_statistics: Usage analytics and management data * - world_chats: Chat session management * - events: Event storage with sequences * - event_sequences: Atomic sequence generation * * Implementation: * - PRAGMA settings for performance and integrity * - JSON column types for flexible configuration storage * - Timestamp tracking for all operations * - Cascading deletes for data consistency * - Prepared statements for security and performance * - 2025-11-02: Refactored to remove migration logic (now in migration-runner.ts) * - 2025-11-02: Schema initialization deprecated - all databases use migration system (0000-0009) * - 2025-11-02: Removed initializeSchema() - migration 0000 handles base schema creation */ import type { Database } from 'sqlite3'; export interface SQLiteConfig { database: string; enableWAL?: boolean; busyTimeout?: number; cacheSize?: number; enableForeignKeys?: boolean; } export interface ArchiveMetadata { sessionName?: string; archiveReason?: string; messageCount: number; startTime?: string; endTime?: string; participants: string[]; tags?: string[]; } export interface ArchiveStatistics { totalArchives: number; totalMessages: number; averageSessionLength: number; mostActiveAgent: string; archiveFrequency: { [key: string]: number; }; } export interface SQLiteSchemaContext { db: Database; config: SQLiteConfig; isInitialized: boolean; } export declare function createSQLiteSchemaContext(config: SQLiteConfig): Promise; export declare function configurePragmas(ctx: { db: Database; config: SQLiteConfig; }): void; /** * @deprecated All schema initialization is now handled by the migration system. * This file only provides utility functions for PRAGMA configuration and database introspection. * Schema creation (tables, indexes, triggers) is defined in migrations/*.sql files. */ export declare function getSchemaVersion(ctx: SQLiteSchemaContext): Promise; export declare function setSchemaVersion(ctx: SQLiteSchemaContext, version: number): Promise; /** * Validate database integrity * Checks for corruption and foreign key constraint violations */ export declare function validateIntegrity(ctx: SQLiteSchemaContext): Promise<{ isValid: boolean; errors: string[]; }>; export declare function getDatabaseStats(ctx: SQLiteSchemaContext): Promise<{ worldCount: number; agentCount: number; activeMemoryCount: number; archiveCount: number; archivedMessageCount: number; databaseSize: number; }>; export declare function closeSchema(ctx: SQLiteSchemaContext): Promise; export declare function getDatabase(ctx: SQLiteSchemaContext): Database;