-- Run once on the server database before deploying the grade approval changes.
CREATE TABLE IF NOT EXISTS grade_edit_requests (
    id INT(11) NOT NULL AUTO_INCREMENT,
    grade_type ENUM('step_grades','results') NOT NULL,
    student_id INT(11) NOT NULL,
    context_id INT(11) NOT NULL,
    requested_by INT(11) NOT NULL,
    reason VARCHAR(500) NULL,
    status ENUM('Pending','Approved','Rejected','Used') NOT NULL DEFAULT 'Pending',
    reviewed_by INT(11) NULL,
    requested_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    reviewed_at TIMESTAMP NULL DEFAULT NULL,
    used_at TIMESTAMP NULL DEFAULT NULL,
    PRIMARY KEY (id),
    KEY idx_lookup (grade_type,student_id,context_id,requested_by,status),
    KEY idx_status (status)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
