diff --git a/remote/cache-service/src/db.rs b/remote/cache-service/src/db.rs index 0831cf8..b9b3579 100644 --- a/remote/cache-service/src/db.rs +++ b/remote/cache-service/src/db.rs @@ -10,7 +10,7 @@ pub fn init(path: &str) -> Result { " CREATE TABLE IF NOT EXISTS current_state ( id INTEGER PRIMARY KEY CHECK (id = 1), - status TEXT, + status TEXT NOT NULL DEFAULT 'offline', timestamp INTEGER, last_seen INTEGER, last_checked INTEGER @@ -29,23 +29,11 @@ pub fn init(path: &str) -> Result { fetched_at INTEGER NOT NULL ); - INSERT OR IGNORE INTO current_state (id, status, timestamp, last_seen, last_checked) VALUES (1, 'offline', NULL, NULL, NULL); + INSERT OR IGNORE INTO current_state (id) VALUES (1); INSERT OR IGNORE INTO pi_info (id, data, fetched_at) VALUES (1, '{}', 0); ", ) .context("failed to initialize database schema")?; - - // Migration: add last_checked column if missing (existing databases) - let has_last_checked: bool = conn - .prepare("SELECT last_checked FROM current_state LIMIT 1") - .is_ok(); - if !has_last_checked { - conn.execute_batch("ALTER TABLE current_state ADD COLUMN last_checked INTEGER")?; - } - - // Migration: convert NULL status to 'offline' - conn.execute("UPDATE current_state SET status = 'offline' WHERE status IS NULL", [])?; - Ok(conn) }