update burn-in schema

This commit is contained in:
grove5_admin committed 2026-05-01 18:12:16 -07:00
1 parent f5e4527b4b
commit f27480b406
2 files changed
+25 -4

No files matched your search

+2 -1
View File
@@ -86,7 +86,8 @@ CREATE TABLE IF NOT EXISTS payloads (
-- Baseline state at time of collection -- Baseline state at time of collection
baseline_established INTEGER, -- bool baseline_established INTEGER, -- bool
baseline_samples INTEGER baseline_samples INTEGER,
burn_in INTEGER -- bool
); );
CREATE INDEX IF NOT EXISTS idx_payloads_chamber ON payloads (chamber_id); CREATE INDEX IF NOT EXISTS idx_payloads_chamber ON payloads (chamber_id);
+23 -3
View File
@@ -98,6 +98,23 @@ async def init_db(db_path: Path = DB_PATH) -> aiosqlite.Connection:
await db.commit() await db.commit()
current_version = 2 current_version = 2
# ── Migration: v3 ────────────────────────────────────────────────────────
# Adds burn_in column to payloads for UI calibration state on refresh.
if current_version < 3:
async with db.execute("PRAGMA table_info(payloads)") as cur:
rows = await cur.fetchall()
payload_cols = {row['name'] for row in rows}
if 'burn_in' not in payload_cols:
await db.execute("ALTER TABLE payloads ADD COLUMN burn_in INTEGER")
await db.execute(
"INSERT OR IGNORE INTO schema_version (version, description) VALUES (?, ?)",
(3, 'Add burn_in column to payloads for UI calibration state'),
)
await db.commit()
current_version = 3
log.info(f"Database ready — schema version {current_version} at {db_path}") log.info(f"Database ready — schema version {current_version} at {db_path}")
return db return db
@@ -204,7 +221,7 @@ async def insert_payload(
co2e_ppm, co2e_confidence, voc_ppb, co2e_ppm, co2e_confidence, voc_ppb,
z1_score, z2_score, z3_score, z1_score, z2_score, z3_score,
scd43_present, temp_delta, humidity_delta, temp_ok, humidity_ok, scd43_present, temp_delta, humidity_delta, temp_ok, humidity_ok,
baseline_established, baseline_samples baseline_established, baseline_samples, burn_in
) VALUES ( ) VALUES (
?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
?, ?, ?, ?, ?, ?, ?, ?,
@@ -213,7 +230,7 @@ async def insert_payload(
?, ?, ?, ?, ?, ?,
?, ?, ?, ?, ?, ?,
?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
?, ? ?, ?, ?
) )
""", """,
( (
@@ -251,6 +268,7 @@ async def insert_payload(
int(raw.baseline.established), int(raw.baseline.established),
raw.baseline.n_samples, raw.baseline.n_samples,
int(raw.burn_in),
), ),
) as cur: ) as cur:
payload_id = cur.lastrowid payload_id = cur.lastrowid
@@ -493,7 +511,9 @@ async def get_environment_history(
z2_score, z2_score,
z3_score, z3_score,
pressure_hpa, pressure_hpa,
baseline_established baseline_established,
baseline_samples,
burn_in
FROM payloads FROM payloads
WHERE chamber_id = ? AND received_at >= ? AND ambient_valid = 1 WHERE chamber_id = ? AND received_at >= ? AND ambient_valid = 1
ORDER BY received_at ASC ORDER BY received_at ASC