-- 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;
