store: migration 0013 — alerts.last_seen_at

This commit is contained in:
2026-05-04 19:16:59 +01:00
parent 4b70939ab5
commit e6d965d7a5
2 changed files with 49 additions and 0 deletions
@@ -0,0 +1,16 @@
-- 0013_alerts_last_seen.sql
--
-- Add alerts.last_seen_at to support open-alert dedup with
-- recurrence-tracking. The engine bumps this column on every tick
-- where a rule still matches an existing open alert, so the UI can
-- render "still happening · Ns ago" without sending a fresh
-- notification.
--
-- Column-level ALTER per CLAUDE.md (no rebuild — alerts has inbound
-- FK from acknowledged_by → users; rebuild would risk cascade).
-- Backfill last_seen_at = created_at for any pre-existing rows so
-- the column is non-null in practice (stays nullable in the schema
-- for forwards-compat with rows that haven't been touched yet).
ALTER TABLE alerts ADD COLUMN last_seen_at TEXT;
UPDATE alerts SET last_seen_at = created_at WHERE last_seen_at IS NULL;