-- OPTIONAL tidy-up. Not required for the fix. Take a backup of `user_shifts` first.
-- Old assignments left "reversed" rows (effective_to earlier than effective_from). Such a row can never match
-- any date, so deleting them does not change any attendance, payroll or task result - it only removes clutter.

-- 1) Preview (how many):
SELECT COUNT(*) AS reversed_rows FROM user_shifts WHERE effective_to < effective_from;

-- 2) Remove them:
DELETE FROM user_shifts WHERE effective_to < effective_from;
