-- Copy of scripts/switch_student_login_to_iin.sql — see that file for the comment.

ALTER TABLE users MODIFY email VARCHAR(255) NULL;

UPDATE users u
JOIN students s ON s.user_id = u.id
SET u.iin = s.iin
WHERE u.role = 'student' AND u.iin IS NULL AND s.iin IS NOT NULL;

UPDATE users SET email = NULL WHERE role = 'student';
