-- Fix FK integrity for commission_rules.salesperson_user_id
-- Makes salesperson_user_id nullable for "general rule" use-cases.

START TRANSACTION;

-- Convert invalid 0 to NULL before enforcing nullable FK semantics.
UPDATE commission_rules
SET salesperson_user_id = NULL
WHERE salesperson_user_id = 0;

-- Ensure column is nullable (INT type kept compatible with users.id in this project).
ALTER TABLE commission_rules
    MODIFY COLUMN salesperson_user_id INT NULL;

COMMIT;
