fix: update schema for no migration, only nukes
This commit is contained in:
parent
e8b60519e7
commit
553d7d1780
1 changed files with 2 additions and 14 deletions
|
|
@ -10,7 +10,7 @@ pub fn init(path: &str) -> Result<Connection> {
|
|||
"
|
||||
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<Connection> {
|
|||
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)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue