Files
accounted/supabase/migrations/20260415120000_salary_review_fixes.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

34 lines
1.7 KiB
SQL

-- =============================================================================
-- Fix 1: Add pension_entry_id to salary_runs
-- Pension journal entries from löneväxling were created but never stored,
-- causing them to be missed during correction reversals.
-- =============================================================================
ALTER TABLE public.salary_runs
ADD COLUMN pension_entry_id uuid REFERENCES public.journal_entries(id);
-- =============================================================================
-- Fix 2: Add UNIQUE constraint on employees(company_id, specification_number)
-- Prevents duplicate FK570 specification numbers from concurrent inserts.
-- The assign_specification_number trigger uses SELECT MAX() without locking,
-- so this constraint makes any race condition fail explicitly.
-- =============================================================================
ALTER TABLE public.employees
ADD CONSTRAINT employees_company_spec_number_unique
UNIQUE (company_id, specification_number);
-- =============================================================================
-- Fix 3: Add avgifter_category to salary_run_employees
-- The avgifter rate alone cannot distinguish between reduced_65plus and
-- vaxa_stod (both 10.21% in 2026). Store the category from the calculation
-- engine so AGI XML generation uses the correct HU rutor breakdown.
-- =============================================================================
ALTER TABLE public.salary_run_employees
ADD COLUMN avgifter_category text
CHECK (avgifter_category IN ('standard', 'reduced_65plus', 'youth', 'vaxa_stod', 'exempt'));
-- Schema reload for PostgREST
NOTIFY pgrst, 'reload schema';