Files
accounted/supabase/migrations/20260522110100_add_invoice_items_vat_columns.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

24 lines
1.1 KiB
SQL

-- Add vat_rate and vat_amount to invoice_items.
--
-- These columns hold the per-line VAT rate and computed VAT amount and
-- back the mixed-rate invoice support documented in CLAUDE.md
-- (generatePerRateLines + getAvailableVatRates). They existed in
-- production since the early invoicing work but were never declared by
-- a migration, so staging, preview branches, and CI databases booted
-- from a fresh migration replay were missing them.
--
-- Defaults match the prod shape: vat_rate defaults to 25 (Swedish
-- standard rate), vat_amount defaults to 0 (lines are recomputed by the
-- engine before persistence). Both NOT NULL because every committed
-- invoice line must carry a deterministic VAT figure for VAT-declaration
-- ruta mapping.
--
-- Application validation: lib/invoices/vat-rules.ts caps vat_rate to
-- the rates allowed for the customer type at the API boundary.
ALTER TABLE public.invoice_items
ADD COLUMN IF NOT EXISTS vat_rate NUMERIC NOT NULL DEFAULT 25,
ADD COLUMN IF NOT EXISTS vat_amount NUMERIC NOT NULL DEFAULT 0;
NOTIFY pgrst, 'reload schema';