diff --git a/backend/migrations/20260908_runtime_schema_consolidation.sql b/backend/migrations/20260908_runtime_schema_consolidation.sql new file mode 100644 index 0000000..acb74a3 --- /dev/null +++ b/backend/migrations/20260908_runtime_schema_consolidation.sql @@ -0,0 +1,34 @@ +-- Consolidates additive schema previously created lazily by request handlers. +-- Run once on staging/production before disabling runtime DDL. + +ALTER TABLE `teachers` + ADD COLUMN `grades_taught` TEXT NULL, + ADD COLUMN `school_name` VARCHAR(255) NULL; + +ALTER TABLE `exam_attempts` + ADD COLUMN `completed_at` TIMESTAMP NULL DEFAULT NULL AFTER `ai_diagnostic_report`; + +CREATE TABLE IF NOT EXISTS `teacher_reviews` ( + `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, + `teacher_id` BIGINT UNSIGNED NOT NULL, + `student_id` BIGINT UNSIGNED NOT NULL, + `course_id` BIGINT UNSIGNED NULL, + `lesson_id` BIGINT UNSIGNED NULL, + `rating_overall` DECIMAL(3,2) NOT NULL DEFAULT 5.00, + `rating_clarity` INT NOT NULL DEFAULT 5, + `rating_response_speed` INT NOT NULL DEFAULT 5, + `rating_socratic_interaction` INT NOT NULL DEFAULT 5, + `review_text` TEXT NULL, + `review_weight` DECIMAL(4,3) NOT NULL DEFAULT 1.000, + `student_watch_percentage` DECIMAL(5,2) NOT NULL DEFAULT 100.00, + `socratic_accuracy_rate` DECIMAL(5,2) NOT NULL DEFAULT 100.00, + `is_flagged_anomaly` TINYINT(1) NOT NULL DEFAULT 0, + `is_verified` TINYINT(1) NOT NULL DEFAULT 1, + `created_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (`id`), + KEY `idx_teacher_reviews_teacher` (`teacher_id`), + KEY `idx_teacher_reviews_student` (`student_id`), + CONSTRAINT `fk_tr_teacher` FOREIGN KEY (`teacher_id`) REFERENCES `teachers` (`id`) ON DELETE CASCADE, + CONSTRAINT `fk_tr_student` FOREIGN KEY (`student_id`) REFERENCES `students` (`id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + diff --git a/docs/IMPLEMENTATION_STATUS.md b/docs/IMPLEMENTATION_STATUS.md index f1729b2..27406ac 100644 --- a/docs/IMPLEMENTATION_STATUS.md +++ b/docs/IMPLEMENTATION_STATUS.md @@ -32,11 +32,12 @@ 1. أخذ نسخة احتياطية مشفرة من قاعدة البيانات. 2. تطبيق `backend/migrations/20260908_secure_identity_and_staff.sql` في نافذة صيانة. -3. تشغيل `backend/scripts/backfill_national_id_hash.php` مرة واحدة بمفاتيح الإنتاج الأصلية. -4. إنشاء أول حساب `super_admin` يدوياً بإجراء تشغيل موثّق، ثم إنشاء بقية حسابات الطاقم من السوبر أدمن. -5. ضبط `JWT_SECRET` و`ENCRYPTION_KEY` و`HMAC_SALT` وRedis وNabeh وR2 من مدير أسرار؛ لا توجد قيم افتراضية في الكود. -6. ترحيل جدول المحادثات القديم—إن كان السيرفر ما زال يستخدم `sender_id/receiver_id`—إلى `sender_identity_id/receiver_identity_id` قبل تشغيل المحادثة. -7. اختبار تكاملي على نسخة staging متصلة فعلياً بـMySQL وRedis وNabeh وR2؛ الفحوص المحلية الحالية لا تثبت اتصال خدمات الإنتاج. +3. تطبيق `backend/migrations/20260908_runtime_schema_consolidation.sql` قبل تعطيل Runtime DDL. +4. تشغيل `backend/scripts/backfill_national_id_hash.php` مرة واحدة بمفاتيح الإنتاج الأصلية. +5. إنشاء أول حساب `super_admin` يدوياً بإجراء تشغيل موثّق، ثم إنشاء بقية حسابات الطاقم من السوبر أدمن. +6. ضبط `JWT_SECRET` و`ENCRYPTION_KEY` و`HMAC_SALT` وRedis وNabeh وR2 من مدير أسرار؛ لا توجد قيم افتراضية في الكود. +7. ترحيل جدول المحادثات القديم—إن كان السيرفر ما زال يستخدم `sender_id/receiver_id`—إلى `sender_identity_id/receiver_identity_id` قبل تشغيل المحادثة. +8. اختبار تكاملي على نسخة staging متصلة فعلياً بـMySQL وRedis وNabeh وR2؛ الفحوص المحلية الحالية لا تثبت اتصال خدمات الإنتاج. ## بوابة إثبات الصف العاشر