1
0

002_sprint_week_active_days.sql 1.3 KB

12345678910111213141516171819202122232425262728293031
  1. -- Phase 12: per-week weekday selection drives Arbeitstage.
  2. --
  3. -- Admins pick which of Mo/Di/Mi/Do/Fr are workdays for each week. The count
  4. -- of selected days (0..5) replaces the previously free-form
  5. -- max_working_days number input on the sprint view.
  6. --
  7. -- Bit layout of active_days_mask:
  8. -- bit 0 = Mo, bit 1 = Di, bit 2 = Mi, bit 3 = Do, bit 4 = Fr
  9. -- Default 31 = 0b11111 → Mo–Fr all active.
  10. --
  11. -- Backfill rule: clamp existing max_working_days to the nearest integer in
  12. -- 0..5 (rounding .5 up) and light up that many leading bits. Half-days go
  13. -- away at the week level; per-worker day cells still carry 0.5 granularity.
  14. ALTER TABLE sprint_weeks
  15. ADD COLUMN active_days_mask INTEGER NOT NULL DEFAULT 31;
  16. -- Backfill existing rows. CAST(x+0.5 AS INTEGER) is SQLite's "round half up"
  17. -- for non-negative x; clamp into 0..5 and derive a mask with the first N
  18. -- bits set: (1 << N) - 1.
  19. UPDATE sprint_weeks
  20. SET active_days_mask = CASE
  21. WHEN CAST(max_working_days + 0.5 AS INTEGER) <= 0 THEN 0
  22. WHEN CAST(max_working_days + 0.5 AS INTEGER) >= 5 THEN 31
  23. ELSE (1 << CAST(max_working_days + 0.5 AS INTEGER)) - 1
  24. END,
  25. max_working_days = CASE
  26. WHEN CAST(max_working_days + 0.5 AS INTEGER) <= 0 THEN 0
  27. WHEN CAST(max_working_days + 0.5 AS INTEGER) >= 5 THEN 5
  28. ELSE CAST(max_working_days + 0.5 AS INTEGER)
  29. END;