feat: Phase 6, Device provisioning and deployment of updates on git-pull

This commit is contained in:
2026-02-27 04:42:41 +02:00
parent 32a2634739
commit 57259c2c2f
19 changed files with 1670 additions and 26 deletions

View File

@@ -0,0 +1,41 @@
import json
import logging
from mqtt.database import get_db
logger = logging.getLogger("manufacturing.audit")
async def log_action(
admin_user: str,
action: str,
serial_number: str | None = None,
detail: dict | None = None,
):
"""Write a manufacturing audit entry to SQLite.
action examples: batch_created, device_flashed, device_assigned, status_updated
"""
try:
db = await get_db()
await db.execute(
"""INSERT INTO mfg_audit_log (admin_user, action, serial_number, detail)
VALUES (?, ?, ?, ?)""",
(
admin_user,
action,
serial_number,
json.dumps(detail) if detail else None,
),
)
await db.commit()
except Exception as e:
logger.error(f"Failed to write audit log: {e}")
async def get_recent(limit: int = 20) -> list[dict]:
db = await get_db()
rows = await db.execute_fetchall(
"SELECT * FROM mfg_audit_log ORDER BY timestamp DESC LIMIT ?",
(limit,),
)
return [dict(r) for r in rows]