-- t-paliad-249 — /inbox overhaul, Slice A.
-- Add a per-user high-watermark read cursor for the inbox feed
-- (approval requests + curated project_events). The cursor advances
-- only when the user POSTs to /api/inbox/mark-all-seen. NULL means
-- "never visited" → every row counts as unread on first paint.
--
-- Note on the carve-out enforced in service code: pending
-- approval_requests count toward the inbox's unread state regardless
-- of this column. The cursor narrows the project_event source only,
-- so a stale cursor never buries a high-value pending approval.
--
-- Design ref: docs/design-inbox-overhaul-2026-05-25.md §3.

ALTER TABLE paliad.users
    ADD COLUMN IF NOT EXISTS inbox_seen_at timestamptz NULL;

COMMENT ON COLUMN paliad.users.inbox_seen_at IS
    'High-watermark cursor for the /inbox feed. project_events newer '
    'than this timestamp are unread for the caller; NULL = never '
    'visited (everything unread). Pending approval_requests bypass '
    'this column and stay unread until decided.';
