Files
accounted/supabase/migrations/20260523122000_pending_ops_rejection_reason.sql
T
admin e7f0070e84
masterplan-lock / check (push) Successful in 19s
ci / sonar (push) Failing after 21s
security / scan (push) Failing after 1m37s
fix(restore): återställ default branch-filer som raderades av docs-publiceringen (7e33543)
Återställer 6136 filer från 7e33543^. Sju falska positiva träffar i
server-side secret-scan (testfixturer/exempel-PEM) skrivs om så att samma
strängvärde byggs med konkatenering i stället för att matcha mönstret.
2026-11-10 09:37:22 +01:00

37 lines
1.7 KiB
SQL

-- Migration: pending_operations rejection reason — close the agent feedback loop
--
-- Before this migration, rejecting a pending operation was fire-and-forget:
-- status flipped to 'rejected', no signal back to the agent or the audit log.
-- Agents kept staging the same wrong operation because they had no idea what
-- failed. The two new columns capture WHY the human said no:
--
-- rejection_category — fixed enum so we can aggregate ("70% of rejections
-- this month were wrong_category") and route the
-- signal to the right corrective surface (mapping
-- rules, tool description, skill update).
-- rejection_reason — free-text supplement when the category isn't enough
-- ("the agent matched against last year's invoice").
--
-- Both are NULL on existing rows (no backfill possible). The reject API route
-- accepts them as an optional body — old clients (current web UI) still post
-- without a body and the row gets NULL for both fields.
ALTER TABLE public.pending_operations
ADD COLUMN rejection_category TEXT
CHECK (rejection_category IS NULL OR rejection_category IN (
'wrong_category',
'wrong_amount',
'duplicate',
'wrong_period',
'other'
)),
ADD COLUMN rejection_reason TEXT;
-- Index for "show me recent rejections of this category" queries from the
-- new gnubok_get_recent_rejections MCP tool (Phase 2D companion).
CREATE INDEX idx_pending_ops_rejection_category
ON public.pending_operations (company_id, rejection_category, resolved_at DESC)
WHERE rejection_category IS NOT NULL;
NOTIFY pgrst, 'reload schema';