-- Student VR login: invitation type + optional email on roster students

DO $$ BEGIN
  ALTER TYPE invitation_type ADD VALUE IF NOT EXISTS 'student';
EXCEPTION
  WHEN duplicate_object THEN NULL;
END $$;

ALTER TABLE students
  ADD COLUMN IF NOT EXISTS email VARCHAR(160);

CREATE UNIQUE INDEX IF NOT EXISTS uq_students_school_email
  ON students (school_id, LOWER(email))
  WHERE email IS NOT NULL;
