Files
accounted/supabase/migrations/20260515090000_invoice_inbox_unique_journal_entry.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

18 lines
745 B
SQL

-- Invoice inbox: enforce one journal entry per inbox item.
--
-- The book-direct route does a check-then-write (409 guard on
-- created_journal_entry_id, then createJournalEntry, then update).
-- Without a UNIQUE constraint, two concurrent calls for the same
-- inbox item can both pass the guard, both insert a journal entry,
-- and the second update overwrites the FK — orphaning the first
-- entry in an immutable ledger with no inbox reference.
--
-- PostgreSQL treats NULLs as distinct in UNIQUE constraints by
-- default, so unbooked items (NULL) remain unconstrained.
ALTER TABLE public.invoice_inbox_items
ADD CONSTRAINT invoice_inbox_items_journal_entry_unique
UNIQUE (created_journal_entry_id);
NOTIFY pgrst, 'reload schema';