Files
accounted/supabase/migrations/20260515200000_webhook_deliveries_updated_at.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

30 lines
1.3 KiB
SQL

-- Migration: webhook_deliveries_updated_at
--
-- Round-4 review on PR #496 — swedish-compliance bot caught that
-- `recoverStuckInFlight` in lib/webhooks/dispatcher.ts queries
-- `webhook_deliveries.updated_at` but the column was never declared.
-- Without an auto-stamped updated_at the in_flight recovery sweep
-- silently returns no rows and stuck deliveries stall forever,
-- breaking the BFNAR 2013:2 kap 8 § audit-log completeness guarantee
-- (every delivery row must reach a terminal state).
--
-- Fix:
-- 1. Add the column with NOT NULL DEFAULT now() so existing rows get
-- a timestamp at backfill time.
-- 2. Reuse the project-wide update_updated_at_column() trigger
-- function so every UPDATE auto-stamps the column.
--
-- The column lands AFTER the immutability triggers from migrations
-- 170000 and 190000, so an UPDATE on a terminal row still hits the
-- BEFORE UPDATE check_violation guard before the trigger has a chance
-- to bump updated_at — no audit-row mutation can occur.
ALTER TABLE public.webhook_deliveries
ADD COLUMN IF NOT EXISTS updated_at timestamptz NOT NULL DEFAULT now();
CREATE OR REPLACE TRIGGER webhook_deliveries_updated_at
BEFORE UPDATE ON public.webhook_deliveries
FOR EACH ROW EXECUTE FUNCTION public.update_updated_at_column();
NOTIFY pgrst, 'reload schema';