v5 migration: add dex_report_date and install_date columns to assets table

This commit is contained in:
2026-05-23 17:26:11 -04:00
parent c9c6317900
commit 900f912147
+11
View File
@@ -457,6 +457,13 @@ def init_db(conn: sqlite3.Connection):
conn.execute("ALTER TABLE assets ADD COLUMN disney_park TEXT DEFAULT NULL")
conn.commit()
# v5 migration: dex_report_date + install_date
if "dex_report_date" not in asset_cols:
conn.execute("ALTER TABLE assets ADD COLUMN dex_report_date TEXT DEFAULT NULL")
if "install_date" not in asset_cols:
conn.execute("ALTER TABLE assets ADD COLUMN install_date TEXT DEFAULT NULL")
conn.commit()
# Ensure service_entrances table exists with correct schema
se_exists = conn.execute(
"SELECT name FROM sqlite_master WHERE type='table' AND name='service_entrances'"
@@ -1005,6 +1012,7 @@ def list_assets(
disney_park: Optional[str] = Query(None),
disney_filter: Optional[str] = Query(None),
q: Optional[str] = Query(None),
no_dex_days: Optional[int] = Query(None, ge=1),
limit: int = Query(100, ge=1, le=2000),
offset: int = Query(0, ge=0),
):
@@ -1044,6 +1052,9 @@ def list_assets(
conditions.append("(name LIKE ? OR machine_id LIKE ? OR serial_number LIKE ? OR description LIKE ?)")
like = f"%{q}%"
params.extend([like, like, like, like])
if no_dex_days is not None:
conditions.append("(dex_report_date IS NULL OR dex_report_date < datetime('now', '-' || ? || ' days'))")
params.append(no_dex_days)
where = " AND ".join(conditions)
sql = "SELECT * FROM assets"