Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aegis-runtime-mv/blob/main/src/persistence/sqlite/schema.rs # aegis-runtime-mv Native Rust agent runtime: Axum WebSocket/SSE/REST gateway, heartbeat scheduler, dependency-aware task workflow, SQLite storage. Attachment of AienOS. Pre-alpha. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aegis-runtime-mv / src / persistence / sqlite / schema.rs` 160 lines ยท 5905 bytes Raw Blame History 1 use rusqlite::Connection; 2 3 pub fn initialize_schema(conn: &Connection) -> Result<(), rusqlite::Error> { 4 let _ = conn.pragma_update(None, "journal_mode", "WAL"); 5 let _ = conn.pragma_update(None, "busy_timeout", 5000); 6 let _ = conn.pragma_update(None, "foreign_keys", "ON"); 7 8 conn.execute_batch( 9 " 10 CREATE TABLE IF NOT EXISTS sessions ( 11 id TEXT PRIMARY KEY, 12 parent_session_id TEXT, 13 status TEXT NOT NULL, 14 objective TEXT, 15 agent_profile TEXT NOT NULL, 16 model_profile TEXT NOT NULL, 17 policy_profile TEXT NOT NULL, 18 budget_json TEXT NOT NULL, 19 created_at INTEGER NOT NULL, 20 updated_at INTEGER NOT NULL, 21 version INTEGER NOT NULL DEFAULT 1 22 ); 23 CREATE INDEX IF NOT EXISTS idx_sessions_updated ON sessions (updated_at DESC); 24 25 CREATE TABLE IF NOT EXISTS messages ( 26 id TEXT PRIMARY KEY, 27 session_id TEXT NOT NULL, 28 role TEXT NOT NULL, 29 data_json TEXT NOT NULL, 30 created_at INTEGER NOT NULL, 31 FOREIGN KEY(session_id) REFERENCES sessions(id) ON DELETE CASCADE 32 ); 33 CREATE INDEX IF NOT EXISTS idx_messages_session ON messages (session_id, created_at ASC); 34 35 CREATE TABLE IF NOT EXISTS runs ( 36 id TEXT PRIMARY KEY, 37 session_id TEXT NOT NULL, 38 state TEXT NOT NULL, 39 trigger_json TEXT NOT NULL, 40 steps_used INTEGER NOT NULL DEFAULT 0, 41 inference_calls_used INTEGER NOT NULL DEFAULT 0, 42 actions_used INTEGER NOT NULL DEFAULT 0, 43 budget_json TEXT NOT NULL, 44 started_at INTEGER NOT NULL, 45 completed_at INTEGER, 46 termination_json TEXT, 47 FOREIGN KEY(session_id) REFERENCES sessions(id) ON DELETE CASCADE 48 ); 49 CREATE INDEX IF NOT EXISTS idx_runs_session ON runs (session_id, started_at DESC); 50 CREATE INDEX IF NOT EXISTS idx_runs_active ON runs (session_id, state); 51 52 CREATE TABLE IF NOT EXISTS actions ( 53 id TEXT PRIMARY KEY, 54 run_id TEXT NOT NULL, 55 session_id TEXT NOT NULL, 56 capability TEXT NOT NULL, 57 intent TEXT NOT NULL, 58 params_json TEXT NOT NULL, 59 status TEXT NOT NULL, 60 receipt_json TEXT, 61 created_at INTEGER NOT NULL, 62 completed_at INTEGER, 63 FOREIGN KEY(session_id) REFERENCES sessions(id) ON DELETE CASCADE, 64 FOREIGN KEY(run_id) REFERENCES runs(id) ON DELETE CASCADE 65 ); 66 CREATE INDEX IF NOT EXISTS idx_actions_run ON actions (run_id, created_at ASC); 67 68 CREATE TABLE IF NOT EXISTS approvals ( 69 id TEXT PRIMARY KEY, 70 action_id TEXT NOT NULL, 71 run_id TEXT NOT NULL, 72 session_id TEXT NOT NULL, 73 prompt TEXT NOT NULL, 74 status TEXT NOT NULL, 75 requested_at INTEGER NOT NULL, 76 decided_at INTEGER, 77 decided_by TEXT, 78 FOREIGN KEY(session_id) REFERENCES sessions(id) ON DELETE CASCADE, 79 FOREIGN KEY(run_id) REFERENCES runs(id) ON DELETE CASCADE, 80 FOREIGN KEY(action_id) REFERENCES actions(id) ON DELETE CASCADE 81 ); 82 CREATE INDEX IF NOT EXISTS idx_approvals_pending ON approvals (status, requested_at ASC); 83 84 CREATE TABLE IF NOT EXISTS audit_events ( 85 id TEXT PRIMARY KEY, 86 sequence INTEGER NOT NULL, 87 session_id TEXT, 88 run_id TEXT, 89 event_type TEXT NOT NULL, 90 payload_json TEXT NOT NULL, 91 prev_hash TEXT NOT NULL, 92 hash TEXT NOT NULL, 93 created_at INTEGER NOT NULL 94 ); 95 CREATE INDEX IF NOT EXISTS idx_audit_sequence ON audit_events (sequence ASC); 96 97 CREATE TABLE IF NOT EXISTS turns ( 98 id INTEGER PRIMARY KEY AUTOINCREMENT, 99 session_id TEXT NOT NULL, 100 role TEXT NOT NULL, 101 prompt TEXT NOT NULL, 102 response TEXT NOT NULL, 103 duration_ms INTEGER NOT NULL, 104 created_at TEXT NOT NULL 105 ); 106 107 CREATE TABLE IF NOT EXISTS heartbeats ( 108 tick_id INTEGER PRIMARY KEY, 109 timestamp TEXT NOT NULL, 110 status TEXT NOT NULL, 111 tasks_scanned INTEGER NOT NULL, 112 actions_dispatched INTEGER NOT NULL, 113 notes TEXT NOT NULL 114 ); 115 116 CREATE TABLE IF NOT EXISTS tasks ( 117 id TEXT PRIMARY KEY, 118 task_type TEXT NOT NULL, 119 payload TEXT NOT NULL, 120 status TEXT NOT NULL, 121 result TEXT, 122 created_at TEXT NOT NULL, 123 completed_at TEXT 124 ); 125 126 CREATE TABLE IF NOT EXISTS task_terminal_events ( 127 event_id TEXT PRIMARY KEY, 128 task_id TEXT NOT NULL UNIQUE, 129 claim_id TEXT NOT NULL, 130 event_json TEXT NOT NULL, 131 exported INTEGER NOT NULL DEFAULT 0 132 ); 133 134 CREATE TABLE IF NOT EXISTS memory_crumbs ( 135 key TEXT PRIMARY KEY, 136 value TEXT NOT NULL, 137 namespace TEXT NOT NULL, 138 created_at TEXT NOT NULL 139 ); 140 141 CREATE TABLE IF NOT EXISTS skills ( 142 name TEXT PRIMARY KEY, 143 description TEXT NOT NULL, 144 command TEXT NOT NULL, 145 updated_at TEXT NOT NULL 146 ); 147 ", 148 )?; 149 let columns = { 150 let mut stmt = conn.prepare("PRAGMA table_info(tasks)")?; 151 let rows = stmt.query_map([], |row| row.get::<_, String>(1))?; 152 rows.collect::, _>>()? 153 }; 154 for column in ["claim_id", "owner_id"] { 155 if !columns.iter().any(|name| name == column) { 156 conn.execute_batch(&format!("ALTER TABLE tasks ADD COLUMN {column} TEXT"))?; 157 } 158 } 159 Ok(()) 160 }