MCPcopy Create free account
hub / github.com/InfinitiBit/graphbit / init_schema_sync

Method init_schema_sync

core/src/memory/store.rs:37–72  ·  view source on GitHub ↗

Create the required tables if they do not already exist.

(&self)

Source from the content-addressed store, hash-verified

35
36 /// Create the required tables if they do not already exist.
37 fn init_schema_sync(&self) -> GraphBitResult<()> {
38 let conn = self
39 .conn
40 .try_lock()
41 .map_err(|_| GraphBitError::memory("Failed to acquire database lock during init"))?;
42
43 conn.execute_batch(
44 "CREATE TABLE IF NOT EXISTS memories (
45 id TEXT PRIMARY KEY,
46 content TEXT NOT NULL,
47 user_id TEXT,
48 agent_id TEXT,
49 run_id TEXT,
50 hash TEXT NOT NULL,
51 metadata TEXT NOT NULL DEFAULT '{}',
52 created_at TEXT NOT NULL,
53 updated_at TEXT NOT NULL
54 );
55 CREATE TABLE IF NOT EXISTS memory_history (
56 id INTEGER PRIMARY KEY AUTOINCREMENT,
57 memory_id TEXT NOT NULL,
58 old_content TEXT NOT NULL DEFAULT '',
59 new_content TEXT NOT NULL DEFAULT '',
60 action TEXT NOT NULL,
61 timestamp TEXT NOT NULL,
62 FOREIGN KEY (memory_id) REFERENCES memories(id) ON DELETE CASCADE
63 );
64 CREATE INDEX IF NOT EXISTS idx_memories_user_id ON memories(user_id);
65 CREATE INDEX IF NOT EXISTS idx_memories_agent_id ON memories(agent_id);
66 CREATE INDEX IF NOT EXISTS idx_memories_run_id ON memories(run_id);
67 CREATE INDEX IF NOT EXISTS idx_memories_hash ON memories(hash);
68 CREATE INDEX IF NOT EXISTS idx_history_memory_id ON memory_history(memory_id);",
69 )?;
70
71 Ok(())
72 }
73
74 /// Insert a new memory.
75 pub async fn insert_memory(&self, memory: &Memory) -> GraphBitResult<()> {

Callers 1

newMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected