-- sql/migrations/staging/003_log_reviews_soft_delete.sql
-- Soft-delete for ai_monitor_log_reviews.
--
-- Previously, deleting a review from the user's history hard-removed the
-- row. The daily-quota counter in the request_review action reads live
-- rows via COUNT(*) ... WHERE requested_at >= CURDATE(), so a user could
-- reset their daily count by deleting history. With deleted_at the row
-- remains for quota accounting but is filtered out of user-visible lists.

ALTER TABLE whp.ai_monitor_log_reviews
    ADD COLUMN IF NOT EXISTS deleted_at DATETIME NULL
        COMMENT 'Soft-delete timestamp; row counts toward daily quota even when hidden from user history.';

-- Helpful index for history queries that now always filter deleted rows.
ALTER TABLE whp.ai_monitor_log_reviews
    ADD INDEX IF NOT EXISTS idx_deleted_at (deleted_at);
