Files
accounted/supabase/migrations/20260729100000_recurring_schedule_dimensions.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

38 lines
2.0 KiB
SQL

-- Recurring schedules carry dimension tags so cron-generated invoices are
-- born with the same {sie_dim_no: code} bags a manually created invoice
-- would have (dimensions PR7 producer parity).
--
-- recurring_invoice_schedules.default_dimensions
-- copied verbatim onto invoices.default_dimensions at spawn time; the
-- invoice entry generators then apply it to every journal line.
-- recurring_invoice_schedule_items.dimensions
-- copied onto invoice_items.dimensions per generated item; merged OVER
-- the invoice default on the revenue line that item books to.
--
-- Same shape + CHECK as invoices/invoice_items (20260702200000). No indexes:
-- read via their parent row when spawning invoices, never containment-queried.
-- NOT NULL DEFAULT '{}' is metadata-only on PG11+ (no table rewrite).
--
-- pg-test: covered-by — plain column adds with a type CHECK, no
-- trigger/RPC/RLS/DEFERRABLE change. Propagation logic is TS-side
-- (lib/invoices/recurring-schedule-service.ts unit tests).
ALTER TABLE public.recurring_invoice_schedules
ADD COLUMN default_dimensions jsonb NOT NULL DEFAULT '{}'::jsonb;
ALTER TABLE public.recurring_invoice_schedules
ADD CONSTRAINT recurring_invoice_schedules_default_dimensions_is_object
CHECK (jsonb_typeof(default_dimensions) = 'object');
ALTER TABLE public.recurring_invoice_schedule_items
ADD COLUMN dimensions jsonb NOT NULL DEFAULT '{}'::jsonb;
ALTER TABLE public.recurring_invoice_schedule_items
ADD CONSTRAINT recurring_invoice_schedule_items_dimensions_is_object
CHECK (jsonb_typeof(dimensions) = 'object');
COMMENT ON COLUMN public.recurring_invoice_schedules.default_dimensions IS
'Dimension bag {sie_dim_no: code} copied onto invoices.default_dimensions for every invoice this schedule generates. See lib/invoices/recurring-schedule-service.ts.';
COMMENT ON COLUMN public.recurring_invoice_schedule_items.dimensions IS
'Per-item dimension bag copied onto invoice_items.dimensions for the generated item; merges over the schedule default on the revenue line.';
NOTIFY pgrst, 'reload schema';