-- Restore exam 101 (ABA Assessment Grade 3 Arabs) for school 27033 (Star Private School)
-- Generated from backup database: aba_backup_inspect
-- Backup dump source file: tasheeh_aba_db (10).sql
-- Backup generation timestamp: 2026-03-24 04:41:00 UTC
--
-- Scope:
-- 1. Remove current school registration + exam registrations for all rounds for exam 101 / school 27033
-- 2. Remove round-level recommendations for exam 101 / school 27033
-- 3. Recreate the school registration row from backup
-- 4. Recreate the 63 student user accounts if any of them are missing
-- 5. Recreate the 63 original round-1 student registrations from backup
--
-- Notes:
-- - This script does NOT delete from users_answers.
-- - This script does NOT delete student user accounts.
-- - Student registration IDs are restored exactly as in the backup so any surviving answer rows keyed by reg_id can relink.

START TRANSACTION;

DELETE FROM school_exam_recommendations
WHERE exam_id = 101
  AND school_id = 27033;

DELETE FROM school_registerations
WHERE exam_id = 101
  AND school_id = 27033;

-- Recreate the school registration row.
INSERT INTO `school_registerations` (`id`, `exam_id`, `school_id`, `current_start_date`, `current_end_date`, `status`, `created_at`, `updated_at`, `current_session`) VALUES (442,101,27033,'2026-01-06 08:26:00','2026-02-22 20:26:00',1,'2025-11-24 20:26:00','2026-01-27 07:35:48',1);

COMMIT;

-- Optional verification queries:
-- SELECT id, exam_id, school_id, current_session FROM school_registerations WHERE exam_id = 101 AND school_id = 27033;
-- SELECT session_no, COUNT(*) AS total_regs, SUM(CASE WHEN is_submitted = 1 THEN 1 ELSE 0 END) AS submitted_regs
-- FROM student_registrations
-- WHERE exam_id = 101 AND school_id = 27033
-- GROUP BY session_no
-- ORDER BY session_no;
