Files
accounted/supabase/migrations/20260802210000_whatsapp_ack_marker.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

20 lines
981 B
SQL

-- WhatsApp conversation layer (PR4): combined-ack bookkeeping.
--
-- The burst debounce sends ONE ack (M4/M5) covering every receipt processed
-- in the window, across webhook invocations. Burst membership must therefore
-- be derivable relationally: an ingested inbound row that no combined ack has
-- covered yet. acked_at is that marker; the winner of the pending_ack claim
-- stamps it on every row its ack covered. The alternative (staging item
-- summaries in whatsapp_conversations.context jsonb) loses items under
-- concurrent read-modify-write from parallel webhook invocations.
ALTER TABLE public.whatsapp_messages
ADD COLUMN IF NOT EXISTS acked_at timestamptz;
-- Winner query: unacked ingested rows for one conversation, oldest first.
CREATE INDEX IF NOT EXISTS whatsapp_messages_unacked
ON public.whatsapp_messages (conversation_id, created_at)
WHERE direction = 'inbound' AND processing_status = 'done' AND acked_at IS NULL;
NOTIFY pgrst, 'reload schema';