Files
accounted/supabase/migrations/20260713110000_employees_work_schedule.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

27 lines
1.2 KiB
SQL

-- Migration: employees work schedule (arbetsschema-lite, payroll gap-closure
-- Phase 4).
--
-- The salary engine has hardcoded 40h/5d assumptions: monthly -> hourly uses
-- divisor 173 (52w x 40h / 12m, CBA convention) and daily rates use divisor
-- 21 (52w x 5d / 12m, rounded). For part-time schedules both are wrong: a
-- 4-day/32-hour employee's sick/VAB deduction should divide by ~17.33, not
-- 21. These two columns parametrize the divisors via
-- lib/salary/work-schedule.ts.
--
-- Precedence: employment_degree keeps prorating BASE SALARY;
-- hours_per_week/workdays_per_week ONLY drive the divisors. They can encode
-- overlapping facts (75% degree vs 30h week); the engine deliberately does
-- not reconcile them.
--
-- Backward compatibility: the helpers return the LEGACY constants (173, 21)
-- exactly when the values equal the defaults, so every existing employee's
-- pay math is byte-identical after this migration.
ALTER TABLE public.employees
ADD COLUMN hours_per_week numeric NOT NULL DEFAULT 40
CHECK (hours_per_week > 0 AND hours_per_week <= 80),
ADD COLUMN workdays_per_week numeric NOT NULL DEFAULT 5
CHECK (workdays_per_week >= 1 AND workdays_per_week <= 7);
NOTIFY pgrst, 'reload schema';