first successful ipad build
Signed-off-by: Sienna Meridian Satterwhite <sienna@r3t.io>
This commit is contained in:
@@ -13,19 +13,8 @@ impl PersistenceManager {
|
||||
pub fn new(db_path: &str) -> Self {
|
||||
let conn = Connection::open(db_path).expect("Failed to open database");
|
||||
|
||||
// Initialize schema (Phase 1 stub - will load from file in Phase 4)
|
||||
let schema = "
|
||||
CREATE TABLE IF NOT EXISTS sessions (
|
||||
id TEXT PRIMARY KEY,
|
||||
state TEXT NOT NULL,
|
||||
created_at INTEGER NOT NULL,
|
||||
last_active_at INTEGER NOT NULL
|
||||
);
|
||||
";
|
||||
|
||||
if let Err(e) = conn.execute_batch(schema) {
|
||||
tracing::warn!("Failed to initialize schema: {}", e);
|
||||
}
|
||||
// Schema is handled by the migration system in persistence/migrations
|
||||
// No hardcoded schema creation here
|
||||
|
||||
Self {
|
||||
conn: Arc::new(Mutex::new(conn)),
|
||||
@@ -35,14 +24,17 @@ impl PersistenceManager {
|
||||
pub fn save_session(&self, session: &Session) -> anyhow::Result<()> {
|
||||
let conn = self.conn.lock().unwrap();
|
||||
|
||||
// Schema from migration 004: id (BLOB), code, name, created_at, last_active, entity_count, state, secret
|
||||
conn.execute(
|
||||
"INSERT OR REPLACE INTO sessions (id, state, created_at, last_active_at)
|
||||
VALUES (?1, ?2, ?3, ?4)",
|
||||
"INSERT OR REPLACE INTO sessions (id, code, state, created_at, last_active, entity_count)
|
||||
VALUES (?1, ?2, ?3, ?4, ?5, ?6)",
|
||||
(
|
||||
session.id.to_code(),
|
||||
session.id.as_uuid().as_bytes(), // id is BLOB in migration 004
|
||||
session.id.to_code(), // code is the text representation
|
||||
format!("{:?}", session.state),
|
||||
session.created_at,
|
||||
session.last_active,
|
||||
0, // entity_count default
|
||||
),
|
||||
)?;
|
||||
|
||||
@@ -53,21 +45,22 @@ impl PersistenceManager {
|
||||
let conn = self.conn.lock().unwrap();
|
||||
|
||||
// Query for the most recently active session
|
||||
// Schema from migration 004: uses last_active (not last_active_at)
|
||||
let mut stmt = conn.prepare(
|
||||
"SELECT id, state, created_at, last_active_at
|
||||
"SELECT code, state, created_at, last_active
|
||||
FROM sessions
|
||||
ORDER BY last_active_at DESC
|
||||
ORDER BY last_active DESC
|
||||
LIMIT 1"
|
||||
)?;
|
||||
|
||||
let session = stmt.query_row([], |row| {
|
||||
let id_code: String = row.get(0)?;
|
||||
let code: String = row.get(0)?;
|
||||
let _state: String = row.get(1)?;
|
||||
let _created_at: String = row.get(2)?;
|
||||
let _last_active_at: String = row.get(3)?;
|
||||
let _created_at: i64 = row.get(2)?;
|
||||
let _last_active: i64 = row.get(3)?;
|
||||
|
||||
// Parse session ID from code
|
||||
if let Ok(session_id) = SessionId::from_code(&id_code) {
|
||||
if let Ok(session_id) = SessionId::from_code(&code) {
|
||||
Ok(Some(Session::new(session_id)))
|
||||
} else {
|
||||
Ok(None)
|
||||
|
||||
Reference in New Issue
Block a user