Files
accounted/supabase/migrations/20260506100000_transactions_document_fk_restrict.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

23 lines
1015 B
SQL

-- Tighten transactions.document_id FK from ON DELETE SET NULL to RESTRICT.
--
-- The original definition (20260505140000) used SET NULL with the assumption
-- that block_document_deletion would catch any deletion of a propagated
-- document before the FK cascade fired. The compliance review flagged this as
-- fragile: trigger ordering could let a SET NULL slip through and silently
-- break the verifikation→underlag link (BFL 5 kap 6 §, 7 kap 1 §).
--
-- RESTRICT means a document with any pinned transaction cannot be deleted at
-- all — the user must explicitly detach first (which goes through the
-- application-layer + DB-level immutability guards). Belt-and-braces with
-- block_document_deletion.
ALTER TABLE public.transactions
DROP CONSTRAINT IF EXISTS transactions_document_id_fkey;
ALTER TABLE public.transactions
ADD CONSTRAINT transactions_document_id_fkey
FOREIGN KEY (document_id) REFERENCES public.document_attachments(id)
ON DELETE RESTRICT;
NOTIFY pgrst, 'reload schema';