- Server: dtc_events table (migrate_phase27_dtc.sql), db.py helpers (upsert_dtc_snapshot, list_dtc_events, delete_dtc_event) - Server API: POST /api/v1/dtc/batch (device auth), GET/DELETE /api/v1/portal/dtc - Server portal: /dtc page with code, description, MIL, status, timestamps, delete - Server nav: DTC history in sidebar + mobile bottom nav - Pi: _upload_dtc_snapshot() in app_upload.py — uploads when snapshot changes, skips when OBD disconnected or unchanged
19 lines
698 B
SQL
19 lines
698 B
SQL
-- Phase 27 / FEAT-05: DTC history synced to remote server.
|
|
-- Pi pushes current DTC snapshot; server diffs against stored state.
|
|
|
|
CREATE TABLE IF NOT EXISTS dtc_events (
|
|
id SERIAL PRIMARY KEY,
|
|
device_id INTEGER NOT NULL REFERENCES devices(id) ON DELETE CASCADE,
|
|
code VARCHAR(10) NOT NULL,
|
|
description TEXT NOT NULL DEFAULT '',
|
|
mil_on BOOLEAN NOT NULL DEFAULT FALSE,
|
|
is_active BOOLEAN NOT NULL DEFAULT TRUE,
|
|
first_seen_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
|
last_seen_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
|
cleared_at TIMESTAMPTZ,
|
|
UNIQUE (device_id, code)
|
|
);
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_dtc_events_device_active
|
|
ON dtc_events (device_id, is_active);
|