-- Migration 4.8 → 4.9
-- Issue 1: feedback_events idempotent key
--   Remove duplicate rows (keep earliest by rowid), then add UNIQUE constraint
--   so retried record() calls don't double-count confidence/context/governance.
DELETE FROM feedback_events
WHERE rowid NOT IN (
    SELECT MIN(rowid) FROM feedback_events GROUP BY trace_id, chunk_id, signal
);

CREATE UNIQUE INDEX IF NOT EXISTS idx_feedback_idempotent
  ON feedback_events(trace_id, chunk_id, signal);
