/// Migration example — shows the migrate_from_neuron API. /// /// This example creates a tiny in-memory SQLite database that mimics the /// Neuron schema, then migrates it into an Engram sled store and prints /// the resulting node count. /// /// In production: /// use engram_core::migration::{migrate_from_neuron, MigrationConfig}; /// let config = MigrationConfig::new( /// PathBuf::from(shellexpand::tilde("~/.neuron/neuron.db").as_ref()), /// PathBuf::from(shellexpand::tilde("~/.engram/neuron").as_ref()), /// ); /// let report = migrate_from_neuron(&config)?; #[cfg(feature = "migration")] fn main() -> Result<(), Box> { use engram_core::migration::{migrate_from_neuron, MigrationConfig}; use rusqlite::Connection; use std::path::PathBuf; // 1. Create a temp Neuron-like SQLite database. let tmp = tempfile::tempdir()?; let sqlite_path = tmp.path().join("neuron.db"); let engram_path = tmp.path().join("engram"); let conn = Connection::open(&sqlite_path)?; conn.execute_batch( "CREATE TABLE memory_nodes ( id TEXT PRIMARY KEY, content TEXT NOT NULL, importance TEXT NOT NULL DEFAULT 'normal', superseded_by TEXT, created_at INTEGER NOT NULL, updated_at INTEGER NOT NULL ); CREATE TABLE knowledge_entries ( id TEXT PRIMARY KEY, title TEXT NOT NULL, content TEXT NOT NULL, category TEXT NOT NULL DEFAULT '', tier TEXT NOT NULL DEFAULT 'note', tags TEXT NOT NULL DEFAULT '', created_at INTEGER NOT NULL, updated_at INTEGER NOT NULL ); CREATE TABLE graph_edges ( from_id TEXT NOT NULL, from_type TEXT NOT NULL, to_id TEXT NOT NULL, to_type TEXT NOT NULL, edge_type TEXT NOT NULL, weight REAL NOT NULL DEFAULT 1.0, PRIMARY KEY (from_id, to_id, edge_type) );", )?; // Insert sample data. for i in 0..5 { conn.execute( "INSERT INTO memory_nodes (id, content, importance, created_at, updated_at) VALUES (?1, ?2, 'normal', 1000, 1000)", rusqlite::params![format!("mem-{i}"), format!("Memory node {i}")], )?; } for i in 0..3 { conn.execute( "INSERT INTO knowledge_entries (id, title, content, created_at, updated_at) VALUES (?1, ?2, ?3, 2000, 2000)", rusqlite::params![ format!("kn-{i}"), format!("Concept {i}"), format!("Body of knowledge entry {i}"), ], )?; } drop(conn); // 2. Run the migration. println!("Running migration..."); let config = MigrationConfig { sqlite_path, engram_path, embedding_dim: 64, }; let report = migrate_from_neuron(&config)?; println!("Migration complete."); println!(" Memories migrated: {}", report.memories_migrated); println!(" Knowledge migrated: {}", report.knowledge_migrated); println!(" Edges created: {}", report.edges_created); if !report.errors.is_empty() { println!(" Errors: {:?}", report.errors); } // 3. Open the result and check counts. let db = engram_core::EngramDb::open(&config.engram_path)?; println!(); println!("Engram node count: {}", db.node_count()?); Ok(()) } #[cfg(not(feature = "migration"))] fn main() { eprintln!("This example requires the 'migration' feature."); eprintln!("Run with: cargo run --example migrate --features migration"); }