Files
accounted/supabase/migrations/20260427150000_invoice_sent_requires_number_check.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
939 B
SQL

-- Belt-and-suspenders for the nullable invoice_number column.
-- Invoices in any status that implies they have left the draft stage must carry
-- a number. ensureInvoiceNumber covers known send paths in application code,
-- but a future caller could transition status without going through that helper
-- and silently produce a sent invoice with no löpnummer (ML 17 kap 24§ violation).
--
-- 'draft' and 'cancelled' are the only statuses where invoice_number may legally
-- be NULL — drafts have not been numbered yet, and cancelled-from-draft never
-- needed one. Cancelled-after-send retains its existing number, so the rule
-- still holds. Status enum from invoices_status_check:
-- draft, sent, paid, partially_paid, overdue, cancelled, credited
ALTER TABLE public.invoices
ADD CONSTRAINT invoices_sent_requires_number
CHECK (status IN ('draft', 'cancelled') OR invoice_number IS NOT NULL);
NOTIFY pgrst, 'reload schema';