Files
accounted/supabase/migrations/20260715120000_credit_note_creation_and_posting_guards.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

21 lines
847 B
SQL

-- Keep partially-created credit notes invisible and prevent duplicate credit
-- relationships or posted vouchers under concurrent requests.
ALTER TABLE public.invoices
ADD COLUMN IF NOT EXISTS creation_complete boolean NOT NULL DEFAULT true;
CREATE UNIQUE INDEX IF NOT EXISTS uq_invoices_company_credited_invoice
ON public.invoices (company_id, credited_invoice_id)
WHERE credited_invoice_id IS NOT NULL;
CREATE UNIQUE INDEX IF NOT EXISTS uq_posted_credit_note_journal_source
ON public.journal_entries (company_id, source_id)
WHERE source_type = 'credit_note'
AND source_id IS NOT NULL
AND status = 'posted';
COMMENT ON COLUMN public.invoices.creation_complete IS
'False only while a credit-note parent and its items are being assembled. API reads must expose only complete credit notes.';
NOTIFY pgrst, 'reload schema';