START TRANSACTION;

-- If the previous ALTER truncated existing values (e.g., 'parent'),
-- temporarily allow both values, fix data, then shrink enum.

-- 1) Expand enum temporarily
ALTER TABLE users MODIFY role ENUM('admin','driver','parent','student') NOT NULL;

-- 2) Repair truncated/invalid roles (common result is empty string)
UPDATE users
SET role = 'student'
WHERE role IS NULL OR role = '';

-- 3) Migrate legacy role
UPDATE users
SET role = 'student'
WHERE role = 'parent';

-- 4) Shrink enum to final allowed roles
ALTER TABLE users MODIFY role ENUM('admin','driver','student') NOT NULL;

COMMIT;
