mgbam commited on
Commit
f617fe9
·
verified ·
1 Parent(s): d40a9c0

Update memory/database.py

Browse files
Files changed (1) hide show
  1. memory/database.py +22 -6
memory/database.py CHANGED
@@ -1,17 +1,27 @@
 
 
1
  import sqlite3
2
  import os
3
 
4
- DB_PATH = os.path.join("/mnt/data", "memory.db")
 
 
5
 
6
  def init_db():
 
 
 
 
 
 
7
  conn = sqlite3.connect(DB_PATH)
8
  c = conn.cursor()
9
  c.execute("""
10
  CREATE TABLE IF NOT EXISTS memory_logs (
11
- id INTEGER PRIMARY KEY AUTOINCREMENT,
12
- agent TEXT,
13
- action TEXT,
14
- result TEXT,
15
  timestamp TEXT
16
  )
17
  """)
@@ -19,10 +29,16 @@ def init_db():
19
  conn.close()
20
 
21
  def log_memory(agent: str, action: str, result: str):
 
 
 
22
  conn = sqlite3.connect(DB_PATH)
23
  c = conn.cursor()
24
  c.execute(
25
- "INSERT INTO memory_logs (agent, action, result, timestamp) VALUES (?,?,?,datetime('now'))",
 
 
 
26
  (agent, action, result)
27
  )
28
  conn.commit()
 
1
+ # memory/database.py
2
+
3
  import sqlite3
4
  import os
5
 
6
+ # 1) Put your DB in /mnt/data so it survives rebuilds and is writable
7
+ DB_DIR = "/mnt/data"
8
+ DB_PATH = os.path.join(DB_DIR, "memory.db")
9
 
10
  def init_db():
11
+ """
12
+ Ensure the data directory and memory_logs table exist.
13
+ """
14
+ # Make sure /mnt/data exists
15
+ os.makedirs(DB_DIR, exist_ok=True)
16
+
17
  conn = sqlite3.connect(DB_PATH)
18
  c = conn.cursor()
19
  c.execute("""
20
  CREATE TABLE IF NOT EXISTS memory_logs (
21
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
22
+ agent TEXT,
23
+ action TEXT,
24
+ result TEXT,
25
  timestamp TEXT
26
  )
27
  """)
 
29
  conn.close()
30
 
31
  def log_memory(agent: str, action: str, result: str):
32
+ """
33
+ Insert a new log row into memory_logs.
34
+ """
35
  conn = sqlite3.connect(DB_PATH)
36
  c = conn.cursor()
37
  c.execute(
38
+ """
39
+ INSERT INTO memory_logs (agent, action, result, timestamp)
40
+ VALUES (?, ?, ?, datetime('now'))
41
+ """,
42
  (agent, action, result)
43
  )
44
  conn.commit()