-- Migration 003 — Phase 7. Daily usage rollup (AGENTS.md §7 retention). -- -- telemetry holds the per-day detail: one row per (device, day, app, domain). -- This table is the daily rollup the dashboard reads for a week and that is -- kept long. Apps and domains are summed into separate columns on purpose: a -- report can carry both for the same session, so adding them together would -- double-count the time. -- -- The rollup is written whenever a telemetry report lands and can be rebuilt -- from telemetry at any time (store.RebuildRollups), so it is derived data, -- never a second source of truth. CREATE TABLE IF NOT EXISTS telemetry_daily ( device_id INTEGER NOT NULL REFERENCES devices(id), day TEXT NOT NULL, -- YYYY-MM-DD, local day app_seconds INTEGER NOT NULL DEFAULT 0, domain_seconds INTEGER NOT NULL DEFAULT 0, app_count INTEGER NOT NULL DEFAULT 0, domain_count INTEGER NOT NULL DEFAULT 0, updated_at TEXT NOT NULL DEFAULT (datetime('now')), PRIMARY KEY (device_id, day) ); CREATE INDEX IF NOT EXISTS idx_telemetry_daily_day ON telemetry_daily(day);