-- Migration 002 — Phase 3. Telemetry reports arrive over MQTT and repeat. -- -- A device reports a rolling daily total ("Spotify: 600 s today"), not a delta, -- so one row per (device, day, app, domain) is the correct shape: a repeat -- report replaces the previous total instead of adding to it. Devices may omit -- the app or the domain, so both default to '' — SQLite treats NULLs in a -- UNIQUE index as distinct, which would defeat the upsert. UPDATE telemetry SET app = '' WHERE app IS NULL; UPDATE telemetry SET domain = '' WHERE domain IS NULL; CREATE UNIQUE INDEX IF NOT EXISTS idx_telemetry_daily ON telemetry(device_id, day, app, domain);