-- =========================================================================
-- NETTOYAGE COMPLET ET FORCÉ - Version Renforcée
-- =========================================================================
-- Ce script supprime TOUT sans exception
-- =========================================================================

SET SQL_SAFE_UPDATES = 0;

START TRANSACTION;

-- Afficher l'état actuel
SELECT '=== AVANT NETTOYAGE ===' as '';
SELECT COUNT(*) as enrollments FROM v2_enrollments;
SELECT COUNT(*) as progress FROM v2_student_seance_progress;
SELECT COUNT(*) as assessments FROM v2_student_assessments;

-- Supprimer TOUTES les données de suivi (avec WHERE 1=1 pour forcer)
DELETE FROM v2_student_assessment_answers WHERE 1=1;
DELETE FROM v2_student_assessments WHERE 1=1;
DELETE FROM v2_student_seance_progress WHERE 1=1;
DELETE FROM v2_student_sessions WHERE 1=1;
DELETE FROM v2_student_quiz_assignments WHERE 1=1;
DELETE FROM v2_student_tests WHERE 1=1;
DELETE FROM v2_enrollments WHERE 1=1;

-- Réinitialiser TOUS les compteurs
UPDATE v2_formations SET student_count = 0 WHERE 1=1;

-- Vérifier que tout est bien supprimé
SELECT '=== APRÈS NETTOYAGE ===' as '';
SELECT COUNT(*) as enrollments FROM v2_enrollments;
SELECT COUNT(*) as progress FROM v2_student_seance_progress;
SELECT COUNT(*) as assessments FROM v2_student_assessments;
SELECT COUNT(*) as answers FROM v2_student_assessment_answers;
SELECT COUNT(*) as sessions FROM v2_student_sessions;

-- Vérifier ce qui est préservé
SELECT '=== DONNÉES PRÉSERVÉES ===' as '';
SELECT COUNT(*) as students FROM v2_students;
SELECT COUNT(*) as formations FROM v2_formations;
SELECT COUNT(*) as seances FROM v2_seances;

-- VALIDER les suppressions
COMMIT;

SET SQL_SAFE_UPDATES = 1;

SELECT '✓✓✓ NETTOYAGE TOTAL TERMINÉ ✓✓✓' as STATUS;
