731 lines
43 KiB
SQL
731 lines
43 KiB
SQL
-- ==============================================================================
|
|
-- SAQEL PLATFORM (منصة صَقِل) - ENTERPRISE MULTI-PERSONA DATABASE SCHEMA (MySQL 8.4+)
|
|
-- Version: 3.0.0 (Enterprise Multi-School, National ID, AI Pedagogical Quality & Fair SLA)
|
|
-- Single Source of Truth for Architecture & Codebase Development
|
|
-- ==============================================================================
|
|
|
|
SET NAMES utf8mb4;
|
|
SET FOREIGN_KEY_CHECKS = 0;
|
|
|
|
-- ------------------------------------------------------------------------------
|
|
-- DROP ALL TABLES IN REVERSE DEPENDENCY ORDER (PRISTINE ZERO-MOCK RESET)
|
|
-- ------------------------------------------------------------------------------
|
|
DROP TABLE IF EXISTS `video_quality_assessments`;
|
|
DROP TABLE IF EXISTS `course_access_passes`;
|
|
DROP TABLE IF EXISTS `teacher_reviews`;
|
|
DROP TABLE IF EXISTS `teacher_performance_metrics`;
|
|
DROP TABLE IF EXISTS `chat_messages`;
|
|
DROP TABLE IF EXISTS `student_mastery_analytics`;
|
|
DROP TABLE IF EXISTS `student_question_answers`;
|
|
DROP TABLE IF EXISTS `exam_attempts`;
|
|
DROP TABLE IF EXISTS `question_options`;
|
|
DROP TABLE IF EXISTS `questions`;
|
|
DROP TABLE IF EXISTS `exams`;
|
|
DROP TABLE IF EXISTS `lesson_progress`;
|
|
DROP TABLE IF EXISTS `lessons`;
|
|
DROP TABLE IF EXISTS `courses`;
|
|
DROP TABLE IF EXISTS `subjects`;
|
|
DROP TABLE IF EXISTS `guardian_students`;
|
|
DROP TABLE IF EXISTS `guardian_link_requests`;
|
|
DROP TABLE IF EXISTS `staff_accounts`;
|
|
DROP TABLE IF EXISTS `guardians`;
|
|
DROP TABLE IF EXISTS `teachers`;
|
|
DROP TABLE IF EXISTS `teacher_profiles`;
|
|
DROP TABLE IF EXISTS `students`;
|
|
DROP TABLE IF EXISTS `school_rosters`;
|
|
DROP TABLE IF EXISTS `schools`;
|
|
DROP TABLE IF EXISTS `user_devices`;
|
|
DROP TABLE IF EXISTS `otp_verifications`;
|
|
DROP TABLE IF EXISTS `auth_identities`;
|
|
DROP TABLE IF EXISTS `users`;
|
|
|
|
-- ------------------------------------------------------------------------------
|
|
-- 1. Table: auth_identities (الهوية المركزية للمصادقة عبر رقم الهاتف وأمان الجلسة)
|
|
-- ------------------------------------------------------------------------------
|
|
CREATE TABLE IF NOT EXISTS `auth_identities` (
|
|
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
|
`uuid` CHAR(36) NOT NULL UNIQUE,
|
|
`phone_number` TEXT NOT NULL,
|
|
`phone_hash` VARCHAR(64) NOT NULL UNIQUE,
|
|
`status` ENUM('active', 'pending_otp', 'suspended') NOT NULL DEFAULT 'active',
|
|
`token_version` INT UNSIGNED NOT NULL DEFAULT 1,
|
|
`created_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
|
|
`updated_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
|
PRIMARY KEY (`id`),
|
|
KEY `idx_identities_phone_hash` (`phone_hash`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- ------------------------------------------------------------------------------
|
|
-- 2. Table: directorates (المظلات المركزية: مديرية الثقافة العسكرية ومجمعات المدارس)
|
|
-- ------------------------------------------------------------------------------
|
|
CREATE TABLE IF NOT EXISTS `directorates` (
|
|
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
|
`uuid` CHAR(36) NOT NULL UNIQUE,
|
|
`code` VARCHAR(50) NOT NULL UNIQUE,
|
|
`name` VARCHAR(255) NOT NULL,
|
|
`type` ENUM('military_culture', 'private_group', 'ministry') NOT NULL DEFAULT 'military_culture',
|
|
`commander_name` VARCHAR(255) DEFAULT NULL,
|
|
`phone` VARCHAR(50) DEFAULT NULL,
|
|
`total_schools` INT UNSIGNED NOT NULL DEFAULT 0,
|
|
`total_students` INT UNSIGNED NOT NULL DEFAULT 0,
|
|
`total_teachers` INT UNSIGNED NOT NULL DEFAULT 0,
|
|
`annual_contract_value` DECIMAL(10, 2) NOT NULL DEFAULT 0.00,
|
|
`is_active` TINYINT(1) NOT NULL DEFAULT 1,
|
|
`created_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
|
|
`updated_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
|
PRIMARY KEY (`id`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- ------------------------------------------------------------------------------
|
|
-- 3. Table: schools (المدارس والفروع التابعة مع تصنيف الوزن والموقع الجغرافي)
|
|
-- ------------------------------------------------------------------------------
|
|
CREATE TABLE IF NOT EXISTS `schools` (
|
|
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
|
`uuid` CHAR(36) NOT NULL UNIQUE,
|
|
`directorate_id` BIGINT UNSIGNED DEFAULT NULL,
|
|
`code` VARCHAR(50) NOT NULL UNIQUE,
|
|
`name` VARCHAR(255) NOT NULL,
|
|
`type` ENUM('military_culture', 'private', 'public', 'center') NOT NULL DEFAULT 'military_culture',
|
|
`weight_tier` ENUM('tier_a_small', 'tier_b_medium', 'tier_c_large') NOT NULL DEFAULT 'tier_b_medium',
|
|
`student_count` INT UNSIGNED NOT NULL DEFAULT 0,
|
|
`teacher_count` INT UNSIGNED NOT NULL DEFAULT 0,
|
|
`director_name` VARCHAR(255) DEFAULT NULL,
|
|
`phone` VARCHAR(50) DEFAULT NULL,
|
|
`city` VARCHAR(100) DEFAULT 'Amman',
|
|
`governorate` VARCHAR(100) DEFAULT 'العاصمة',
|
|
`latitude` DECIMAL(10, 8) DEFAULT 31.9539,
|
|
`longitude` DECIMAL(11, 8) DEFAULT 35.9106,
|
|
`is_active` TINYINT(1) NOT NULL DEFAULT 1,
|
|
`subscription_status` ENUM('active', 'trial', 'expired') NOT NULL DEFAULT 'active',
|
|
`annual_fee` DECIMAL(8, 2) NOT NULL DEFAULT 450.00,
|
|
`contract_expires_at` TIMESTAMP NULL DEFAULT NULL,
|
|
`created_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
|
|
`updated_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
|
PRIMARY KEY (`id`),
|
|
KEY `idx_schools_directorate` (`directorate_id`),
|
|
CONSTRAINT `fk_school_directorate` FOREIGN KEY (`directorate_id`) REFERENCES `directorates` (`id`) ON DELETE SET NULL
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- ------------------------------------------------------------------------------
|
|
-- 4. Table: field_recorded_lessons (الحصص الميدانية المرئية المصورة عبر تطبيق المشرف)
|
|
-- ------------------------------------------------------------------------------
|
|
CREATE TABLE IF NOT EXISTS `field_recorded_lessons` (
|
|
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
|
`uuid` CHAR(36) NOT NULL UNIQUE,
|
|
`school_id` BIGINT UNSIGNED NOT NULL,
|
|
`teacher_id` BIGINT UNSIGNED NOT NULL,
|
|
`subject` VARCHAR(100) NOT NULL,
|
|
`grade_level` VARCHAR(50) NOT NULL,
|
|
`lesson_title` VARCHAR(255) NOT NULL,
|
|
`video_path` VARCHAR(500) NOT NULL,
|
|
`file_size_mb` DECIMAL(8, 2) NOT NULL DEFAULT 0.00,
|
|
`duration_minutes` INT UNSIGNED NOT NULL DEFAULT 0,
|
|
`ai_alignment_score` DECIMAL(5, 2) DEFAULT NULL,
|
|
`teacher_talk_ratio` DECIMAL(5, 2) DEFAULT NULL,
|
|
`pedagogical_report_json` JSON DEFAULT NULL,
|
|
`socratic_checkpoints_json` JSON DEFAULT NULL,
|
|
`status` ENUM('pending_ai', 'under_supervisor_review', 'approved', 'rejected') NOT NULL DEFAULT 'pending_ai',
|
|
`recorded_by_name` VARCHAR(255) NOT NULL,
|
|
`recorded_by_role` ENUM('principal', 'supervisor') NOT NULL DEFAULT 'principal',
|
|
`recorded_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
`created_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
|
|
PRIMARY KEY (`id`),
|
|
KEY `idx_recorded_school` (`school_id`),
|
|
KEY `idx_recorded_teacher` (`teacher_id`),
|
|
CONSTRAINT `fk_recorded_school` FOREIGN KEY (`school_id`) REFERENCES `schools` (`id`) ON DELETE CASCADE
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- ------------------------------------------------------------------------------
|
|
-- 5. Table: unified_exams (الامتحانات الموحدة بنكهة التوجيهي الوزاري)
|
|
-- ------------------------------------------------------------------------------
|
|
CREATE TABLE IF NOT EXISTS `unified_exams` (
|
|
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
|
`uuid` CHAR(36) NOT NULL UNIQUE,
|
|
`directorate_id` BIGINT UNSIGNED NOT NULL,
|
|
`code` VARCHAR(50) NOT NULL UNIQUE,
|
|
`title` VARCHAR(255) NOT NULL,
|
|
`subject` VARCHAR(100) NOT NULL,
|
|
`grade_level` VARCHAR(50) NOT NULL,
|
|
`scheduled_at` DATETIME NOT NULL,
|
|
`duration_minutes` INT UNSIGNED NOT NULL DEFAULT 60,
|
|
`form_a_json` JSON NOT NULL,
|
|
`form_b_json` JSON NOT NULL,
|
|
`answer_key_json` JSON NOT NULL,
|
|
`status` ENUM('draft', 'scheduled', 'in_progress', 'completed') NOT NULL DEFAULT 'scheduled',
|
|
`created_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
|
|
PRIMARY KEY (`id`),
|
|
KEY `idx_unified_directorate` (`directorate_id`),
|
|
CONSTRAINT `fk_unified_directorate` FOREIGN KEY (`directorate_id`) REFERENCES `directorates` (`id`) ON DELETE CASCADE
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- ------------------------------------------------------------------------------
|
|
-- 6. Table: exam_school_sessions (جلسات الامتحان في كل مدرسة ومكافحة الغش)
|
|
-- ------------------------------------------------------------------------------
|
|
CREATE TABLE IF NOT EXISTS `exam_school_sessions` (
|
|
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
|
`unified_exam_id` BIGINT UNSIGNED NOT NULL,
|
|
`school_id` BIGINT UNSIGNED NOT NULL,
|
|
`total_students` INT UNSIGNED NOT NULL DEFAULT 0,
|
|
`completed_count` INT UNSIGNED NOT NULL DEFAULT 0,
|
|
`pushed_to_lab` TINYINT(1) NOT NULL DEFAULT 0,
|
|
`pushed_to_lab_at` DATETIME DEFAULT NULL,
|
|
`speed_anomalies_count` INT UNSIGNED NOT NULL DEFAULT 0,
|
|
`error_clustering_count` INT UNSIGNED NOT NULL DEFAULT 0,
|
|
`panoramic_video_path` VARCHAR(500) DEFAULT NULL,
|
|
`panoramic_size_mb` DECIMAL(8, 2) DEFAULT 0.00,
|
|
`status` ENUM('ready', 'in_progress', 'submitted', 'flagged_investigation') NOT NULL DEFAULT 'ready',
|
|
`created_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
|
|
PRIMARY KEY (`id`),
|
|
UNIQUE KEY `idx_exam_school` (`unified_exam_id`, `school_id`),
|
|
CONSTRAINT `fk_session_exam` FOREIGN KEY (`unified_exam_id`) REFERENCES `unified_exams` (`id`) ON DELETE CASCADE,
|
|
CONSTRAINT `fk_session_school` FOREIGN KEY (`school_id`) REFERENCES `schools` (`id`) ON DELETE CASCADE
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- ------------------------------------------------------------------------------
|
|
-- 3. Table: school_rosters (كشوفات المدارس المعتمدة بالرقم الوطني والربط التلقائي)
|
|
-- ------------------------------------------------------------------------------
|
|
CREATE TABLE IF NOT EXISTS `school_rosters` (
|
|
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
|
`school_id` BIGINT UNSIGNED NOT NULL,
|
|
`national_id` TEXT NOT NULL,
|
|
`national_id_hash` CHAR(64) NOT NULL,
|
|
`student_full_name` VARCHAR(255) NOT NULL,
|
|
`grade_level` VARCHAR(50) NOT NULL DEFAULT 'tawjihi_2008',
|
|
`stream` ENUM('scientific', 'literary', 'vocational', 'general') NOT NULL DEFAULT 'scientific',
|
|
`is_claimed` TINYINT(1) NOT NULL DEFAULT 0,
|
|
`claimed_student_id` BIGINT UNSIGNED DEFAULT NULL,
|
|
`created_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
|
|
PRIMARY KEY (`id`),
|
|
UNIQUE KEY `idx_school_national_id` (`school_id`, `national_id_hash`),
|
|
KEY `idx_roster_national_id` (`national_id_hash`),
|
|
CONSTRAINT `fk_roster_school` FOREIGN KEY (`school_id`) REFERENCES `schools` (`id`) ON DELETE CASCADE
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- ------------------------------------------------------------------------------
|
|
-- 4. Table: students (جدول الطلاب المستقل بالرقم الوطني والمدرسة)
|
|
-- ------------------------------------------------------------------------------
|
|
CREATE TABLE IF NOT EXISTS `students` (
|
|
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
|
`uuid` CHAR(36) NOT NULL UNIQUE,
|
|
`identity_id` BIGINT UNSIGNED DEFAULT NULL,
|
|
`school_id` BIGINT UNSIGNED DEFAULT NULL,
|
|
`national_id` TEXT NOT NULL,
|
|
`national_id_hash` CHAR(64) NOT NULL UNIQUE,
|
|
`full_name` VARCHAR(255) NOT NULL,
|
|
`pin_code_hash` VARCHAR(255) DEFAULT NULL,
|
|
`grade_level` VARCHAR(50) NOT NULL DEFAULT 'tawjihi_2008',
|
|
`stream` ENUM('scientific', 'literary', 'vocational', 'general') NOT NULL DEFAULT 'scientific',
|
|
`is_school_sponsored` TINYINT(1) NOT NULL DEFAULT 0,
|
|
`readiness_score` DECIMAL(5, 2) NOT NULL DEFAULT 0.00,
|
|
`created_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
|
|
`updated_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
|
PRIMARY KEY (`id`),
|
|
KEY `idx_students_identity` (`identity_id`),
|
|
KEY `idx_students_school` (`school_id`),
|
|
KEY `idx_students_national_id` (`national_id_hash`),
|
|
CONSTRAINT `fk_student_identity` FOREIGN KEY (`identity_id`) REFERENCES `auth_identities` (`id`) ON DELETE SET NULL,
|
|
CONSTRAINT `fk_student_school` FOREIGN KEY (`school_id`) REFERENCES `schools` (`id`) ON DELETE SET NULL
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- ------------------------------------------------------------------------------
|
|
-- 5. Table: guardians (جدول أولياء الأمور المستقل)
|
|
-- ------------------------------------------------------------------------------
|
|
CREATE TABLE IF NOT EXISTS `guardians` (
|
|
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
|
`uuid` CHAR(36) NOT NULL UNIQUE,
|
|
`identity_id` BIGINT UNSIGNED NOT NULL UNIQUE,
|
|
`national_id` VARCHAR(20) DEFAULT NULL,
|
|
`full_name` VARCHAR(255) NOT NULL,
|
|
`created_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
|
|
`updated_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
|
PRIMARY KEY (`id`),
|
|
CONSTRAINT `fk_guardian_identity` FOREIGN KEY (`identity_id`) REFERENCES `auth_identities` (`id`) ON DELETE CASCADE
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- ------------------------------------------------------------------------------
|
|
-- 6. Table: guardian_students (ربط ولي الأمر بالأبناء المتعددين 1:N)
|
|
-- ------------------------------------------------------------------------------
|
|
CREATE TABLE IF NOT EXISTS `guardian_students` (
|
|
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
|
`guardian_id` BIGINT UNSIGNED NOT NULL,
|
|
`student_id` BIGINT UNSIGNED NOT NULL,
|
|
`relationship_type` ENUM('father', 'mother', 'brother', 'guardian') NOT NULL DEFAULT 'father',
|
|
`can_view_analytics` TINYINT(1) NOT NULL DEFAULT 1,
|
|
`created_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
|
|
PRIMARY KEY (`id`),
|
|
UNIQUE KEY `idx_guardian_student_pair` (`guardian_id`, `student_id`),
|
|
CONSTRAINT `fk_gsp_guardian` FOREIGN KEY (`guardian_id`) REFERENCES `guardians` (`id`) ON DELETE CASCADE,
|
|
CONSTRAINT `fk_gsp_student` FOREIGN KEY (`student_id`) REFERENCES `students` (`id`) ON DELETE CASCADE
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS `guardian_link_requests` (
|
|
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
|
`uuid` CHAR(36) NOT NULL UNIQUE,
|
|
`guardian_id` BIGINT UNSIGNED NOT NULL,
|
|
`student_id` BIGINT UNSIGNED NOT NULL,
|
|
`relationship_type` ENUM('father', 'mother', 'brother', 'guardian') NOT NULL DEFAULT 'guardian',
|
|
`status` ENUM('pending', 'approved', 'rejected', 'cancelled') NOT NULL DEFAULT 'pending',
|
|
`reviewed_at` TIMESTAMP NULL DEFAULT NULL,
|
|
`created_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
|
|
PRIMARY KEY (`id`),
|
|
UNIQUE KEY `uq_guardian_link_pending` (`guardian_id`, `student_id`, `status`),
|
|
CONSTRAINT `fk_link_request_guardian` FOREIGN KEY (`guardian_id`) REFERENCES `guardians` (`id`) ON DELETE CASCADE,
|
|
CONSTRAINT `fk_link_request_student` FOREIGN KEY (`student_id`) REFERENCES `students` (`id`) ON DELETE CASCADE
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- ------------------------------------------------------------------------------
|
|
-- Institutional staff are provisioned by an existing super admin. OTP login
|
|
-- never creates these privileged accounts from a client-supplied role.
|
|
-- ------------------------------------------------------------------------------
|
|
CREATE TABLE IF NOT EXISTS `staff_accounts` (
|
|
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
|
`uuid` CHAR(36) NOT NULL UNIQUE,
|
|
`identity_id` BIGINT UNSIGNED NOT NULL,
|
|
`full_name` VARCHAR(255) NOT NULL,
|
|
`role` ENUM('school_admin', 'directorate_admin', 'supervisor', 'super_admin') NOT NULL,
|
|
`school_id` BIGINT UNSIGNED DEFAULT NULL,
|
|
`directorate_id` BIGINT UNSIGNED DEFAULT NULL,
|
|
`status` ENUM('active', 'suspended') NOT NULL DEFAULT 'active',
|
|
`created_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
|
|
`updated_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
|
PRIMARY KEY (`id`),
|
|
UNIQUE KEY `idx_staff_identity_role` (`identity_id`, `role`),
|
|
KEY `idx_staff_school` (`school_id`),
|
|
KEY `idx_staff_directorate` (`directorate_id`),
|
|
CONSTRAINT `fk_staff_identity` FOREIGN KEY (`identity_id`) REFERENCES `auth_identities` (`id`) ON DELETE CASCADE,
|
|
CONSTRAINT `fk_staff_school` FOREIGN KEY (`school_id`) REFERENCES `schools` (`id`) ON DELETE SET NULL,
|
|
CONSTRAINT `fk_staff_directorate` FOREIGN KEY (`directorate_id`) REFERENCES `directorates` (`id`) ON DELETE SET NULL
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- ------------------------------------------------------------------------------
|
|
-- 7. Table: teachers (جدول المعلمين المستقل وتحديد المدرسة والاختصاص)
|
|
-- ------------------------------------------------------------------------------
|
|
CREATE TABLE IF NOT EXISTS `teachers` (
|
|
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
|
`uuid` CHAR(36) NOT NULL UNIQUE,
|
|
`identity_id` BIGINT UNSIGNED NOT NULL UNIQUE,
|
|
`school_id` BIGINT UNSIGNED DEFAULT NULL,
|
|
`national_id` VARCHAR(20) DEFAULT NULL,
|
|
`full_name` VARCHAR(255) NOT NULL,
|
|
`specialization` VARCHAR(150) NOT NULL DEFAULT 'الرياضيات العلمي',
|
|
`bio` TEXT DEFAULT NULL,
|
|
`is_school_exclusive` TINYINT(1) NOT NULL DEFAULT 0,
|
|
`is_marketplace_public` TINYINT(1) NOT NULL DEFAULT 1,
|
|
`created_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
|
|
`updated_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
|
PRIMARY KEY (`id`),
|
|
KEY `idx_teachers_school` (`school_id`),
|
|
CONSTRAINT `fk_teacher_identity` FOREIGN KEY (`identity_id`) REFERENCES `auth_identities` (`id`) ON DELETE CASCADE,
|
|
CONSTRAINT `fk_teacher_school` FOREIGN KEY (`school_id`) REFERENCES `schools` (`id`) ON DELETE SET NULL
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- ------------------------------------------------------------------------------
|
|
-- 8. Table: subjects (المباحث الدراسية المعتمدة - التوجيهي والثقافة العسكرية)
|
|
-- ------------------------------------------------------------------------------
|
|
CREATE TABLE IF NOT EXISTS `subjects` (
|
|
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
|
`name` VARCHAR(150) NOT NULL,
|
|
`code` VARCHAR(50) NOT NULL UNIQUE,
|
|
`stream` ENUM('scientific', 'literary', 'vocational', 'common') NOT NULL DEFAULT 'scientific',
|
|
`is_active` TINYINT(1) NOT NULL DEFAULT 1,
|
|
`created_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
|
|
PRIMARY KEY (`id`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- ------------------------------------------------------------------------------
|
|
-- 9. Table: courses (الدورات التدريبية المربوطة بالمعلم والمادة والمدرسة)
|
|
-- ------------------------------------------------------------------------------
|
|
CREATE TABLE IF NOT EXISTS `courses` (
|
|
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
|
`uuid` CHAR(36) NOT NULL UNIQUE,
|
|
`subject_id` BIGINT UNSIGNED NOT NULL,
|
|
`teacher_id` BIGINT UNSIGNED NOT NULL,
|
|
`school_id` BIGINT UNSIGNED DEFAULT NULL,
|
|
`title` VARCHAR(255) NOT NULL,
|
|
`description` TEXT DEFAULT NULL,
|
|
`semester` ENUM('first', 'second', 'full_year', 'intensive') NOT NULL DEFAULT 'first',
|
|
`price_jod` DECIMAL(8, 2) NOT NULL DEFAULT 35.00,
|
|
`thumbnail_url` VARCHAR(500) DEFAULT NULL,
|
|
`is_school_exclusive` TINYINT(1) NOT NULL DEFAULT 0,
|
|
`is_system_curriculum` TINYINT(1) NOT NULL DEFAULT 0 COMMENT 'الدورة الرئيسية للمنهاج الوزاري — تُستخدم لرفع فيديوهات الذكاء الاصطناعي',
|
|
`grade_level` VARCHAR(50) DEFAULT NULL COMMENT 'المرحلة الدراسية مثل: tawjihi_2008',
|
|
`stream` ENUM('scientific','literary','vocational','general') DEFAULT NULL COMMENT 'الفرع الدراسي',
|
|
`is_published` TINYINT(1) NOT NULL DEFAULT 1,
|
|
`created_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
|
|
`updated_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
|
PRIMARY KEY (`id`),
|
|
KEY `idx_courses_subject` (`subject_id`),
|
|
KEY `idx_courses_teacher` (`teacher_id`),
|
|
KEY `idx_courses_school` (`school_id`),
|
|
KEY `idx_courses_grade_stream` (`grade_level`, `stream`),
|
|
KEY `idx_courses_system` (`is_system_curriculum`),
|
|
CONSTRAINT `fk_courses_subject` FOREIGN KEY (`subject_id`) REFERENCES `subjects` (`id`) ON DELETE RESTRICT,
|
|
CONSTRAINT `fk_courses_teacher` FOREIGN KEY (`teacher_id`) REFERENCES `teachers` (`id`) ON DELETE CASCADE,
|
|
CONSTRAINT `fk_courses_school` FOREIGN KEY (`school_id`) REFERENCES `schools` (`id`) ON DELETE SET NULL
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- ------------------------------------------------------------------------------
|
|
-- 10. Table: lessons (الدروس وبث HLS المقسم عبر Cloudflare R2 والفهرس الزمني)
|
|
-- ------------------------------------------------------------------------------
|
|
CREATE TABLE IF NOT EXISTS `lessons` (
|
|
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
|
`course_id` BIGINT UNSIGNED NOT NULL,
|
|
`title` VARCHAR(255) NOT NULL,
|
|
`curriculum_key` VARCHAR(500) DEFAULT NULL COMMENT 'المسار الفريد لدرس الـManifest داخل storage/curriculum',
|
|
`sequence_order` INT UNSIGNED NOT NULL DEFAULT 1,
|
|
|
|
-- المعلم الحقيقي (Teacher Video)
|
|
`video_uuid` VARCHAR(64) DEFAULT NULL,
|
|
`storage_type` ENUM('bunny_stream', 'api_upload', 'external_url') NOT NULL DEFAULT 'bunny_stream',
|
|
`local_path` VARCHAR(500) DEFAULT NULL,
|
|
`hls_url` VARCHAR(500) DEFAULT NULL,
|
|
`thumbnail_url` VARCHAR(500) DEFAULT NULL,
|
|
`encoding_status` ENUM('pending', 'processing', 'ready', 'failed') NOT NULL DEFAULT 'ready',
|
|
`timeline_chapters_json` JSON DEFAULT NULL,
|
|
`bunny_video_id` VARCHAR(100) DEFAULT NULL,
|
|
`duration_seconds` INT UNSIGNED NOT NULL DEFAULT 0,
|
|
|
|
-- الذكاء الاصطناعي (NotebookLM / AI Audio-Video Explanations)
|
|
`ai_podcast_url` VARCHAR(500) DEFAULT NULL COMMENT 'رابط الشرح الصوتي المولد بالذكاء الاصطناعي (NotebookLM style)',
|
|
`ai_video_url` VARCHAR(500) DEFAULT NULL COMMENT 'رابط فيديو الشرح الآلي بالذكاء الاصطناعي',
|
|
|
|
-- المحتوى النصي المفرغ من الـ PDF والتوليد الذكي
|
|
`markdown_content` LONGTEXT DEFAULT NULL COMMENT 'محتوى الدرس النصي بصيغة Markdown و LaTeX',
|
|
`cheat_sheet_markdown` LONGTEXT DEFAULT NULL COMMENT 'ملخص الدرس السريع (Cheat Sheet)',
|
|
`socratic_quiz_json` JSON DEFAULT NULL COMMENT 'الفحص السقراطي الذكي (سؤال وجواب)',
|
|
`interactive_lab_json` JSON DEFAULT NULL COMMENT 'المختبر التفاعلي المسبق التجهيز (أمثلة الكتاب الوزاري + التمارين الذكية المخبوزة)',
|
|
|
|
`is_free_preview` TINYINT(1) NOT NULL DEFAULT 0,
|
|
`created_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
|
|
`updated_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
|
PRIMARY KEY (`id`),
|
|
KEY `idx_lessons_course` (`course_id`),
|
|
KEY `idx_lessons_curriculum_key` (`curriculum_key`),
|
|
KEY `idx_lessons_video_uuid` (`video_uuid`),
|
|
CONSTRAINT `fk_lessons_course` FOREIGN KEY (`course_id`) REFERENCES `courses` (`id`) ON DELETE CASCADE
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- ------------------------------------------------------------------------------
|
|
-- 10.6. Table: lesson_progress (تقدم المشاهدة الفعلي لكل طالب)
|
|
-- ------------------------------------------------------------------------------
|
|
CREATE TABLE IF NOT EXISTS `lesson_progress` (
|
|
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
|
`student_id` BIGINT UNSIGNED NOT NULL,
|
|
`lesson_id` BIGINT UNSIGNED NOT NULL,
|
|
`position_seconds` INT UNSIGNED NOT NULL DEFAULT 0,
|
|
`watched_seconds` INT UNSIGNED NOT NULL DEFAULT 0,
|
|
`completion_percentage` DECIMAL(5,2) NOT NULL DEFAULT 0.00,
|
|
`is_completed` TINYINT(1) NOT NULL DEFAULT 0,
|
|
`last_seen_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
|
|
`completed_at` TIMESTAMP NULL DEFAULT NULL,
|
|
PRIMARY KEY (`id`),
|
|
UNIQUE KEY `idx_progress_student_lesson` (`student_id`, `lesson_id`),
|
|
KEY `idx_progress_lesson` (`lesson_id`),
|
|
CONSTRAINT `fk_progress_student` FOREIGN KEY (`student_id`) REFERENCES `students` (`id`) ON DELETE CASCADE,
|
|
CONSTRAINT `fk_progress_lesson` FOREIGN KEY (`lesson_id`) REFERENCES `lessons` (`id`) ON DELETE CASCADE
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- ------------------------------------------------------------------------------
|
|
-- 10.7. Table: student_mastery_analytics (المؤشر التراكمي للطالب)
|
|
-- ------------------------------------------------------------------------------
|
|
CREATE TABLE IF NOT EXISTS `student_mastery_analytics` (
|
|
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
|
`student_id` BIGINT UNSIGNED NOT NULL,
|
|
`course_id` BIGINT UNSIGNED NOT NULL,
|
|
`subject_id` BIGINT UNSIGNED NOT NULL,
|
|
`mastery_percentage` DECIMAL(5,2) NOT NULL DEFAULT 0.00,
|
|
`tawjihi_readiness_score` DECIMAL(5,2) NOT NULL DEFAULT 0.00,
|
|
`exams_passed_count` INT UNSIGNED NOT NULL DEFAULT 0,
|
|
`exams_total_count` INT UNSIGNED NOT NULL DEFAULT 0,
|
|
`updated_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
|
PRIMARY KEY (`id`),
|
|
UNIQUE KEY `idx_mastery_student_course` (`student_id`, `course_id`),
|
|
CONSTRAINT `fk_mastery_student` FOREIGN KEY (`student_id`) REFERENCES `students` (`id`) ON DELETE CASCADE,
|
|
CONSTRAINT `fk_mastery_course` FOREIGN KEY (`course_id`) REFERENCES `courses` (`id`) ON DELETE CASCADE,
|
|
CONSTRAINT `fk_mastery_subject` FOREIGN KEY (`subject_id`) REFERENCES `subjects` (`id`) ON DELETE CASCADE
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- ------------------------------------------------------------------------------
|
|
-- 10.5. Table: lesson_resources (المصادر المرفقة للدرس: كتب، ملخصات، أوراق عمل PDF)
|
|
-- ------------------------------------------------------------------------------
|
|
CREATE TABLE IF NOT EXISTS `lesson_resources` (
|
|
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
|
`lesson_id` BIGINT UNSIGNED NOT NULL,
|
|
`title` VARCHAR(255) NOT NULL,
|
|
`resource_type` ENUM('book_pdf', 'summary_pdf', 'worksheet_pdf', 'external_link') NOT NULL DEFAULT 'summary_pdf',
|
|
`file_url` VARCHAR(500) NOT NULL,
|
|
`is_ai_generated` TINYINT(1) NOT NULL DEFAULT 0,
|
|
`created_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
|
|
PRIMARY KEY (`id`),
|
|
KEY `idx_resources_lesson` (`lesson_id`),
|
|
CONSTRAINT `fk_resources_lesson` FOREIGN KEY (`lesson_id`) REFERENCES `lessons` (`id`) ON DELETE CASCADE
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- ------------------------------------------------------------------------------
|
|
-- 11. Table: video_quality_assessments (تقييم جودة المحتوى التعليمي والتوافق بالذكاء الاصطناعي)
|
|
-- ------------------------------------------------------------------------------
|
|
CREATE TABLE IF NOT EXISTS `video_quality_assessments` (
|
|
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
|
`lesson_id` BIGINT UNSIGNED NOT NULL UNIQUE,
|
|
`curriculum_alignment_score` DECIMAL(5, 2) NOT NULL DEFAULT 95.00,
|
|
`pedagogical_clarity_score` DECIMAL(5, 2) NOT NULL DEFAULT 92.00,
|
|
`learning_outcomes_json` JSON DEFAULT NULL,
|
|
`bloom_coverage_json` JSON DEFAULT NULL,
|
|
`ai_critique_text` TEXT DEFAULT NULL,
|
|
`approval_status` ENUM('approved_official', 'needs_revision', 'pending_ai') NOT NULL DEFAULT 'approved_official',
|
|
`evaluated_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
|
|
PRIMARY KEY (`id`),
|
|
CONSTRAINT `fk_vqa_lesson` FOREIGN KEY (`lesson_id`) REFERENCES `lessons` (`id`) ON DELETE CASCADE
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- ------------------------------------------------------------------------------
|
|
-- 12. Table: exams (الامتحانات وبنوك الأسئلة التكيفية: فحص سقراطي، امتحان درس، وحدة، وامتحان وزاري)
|
|
-- ------------------------------------------------------------------------------
|
|
CREATE TABLE IF NOT EXISTS `exams` (
|
|
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
|
`uuid` CHAR(36) NOT NULL UNIQUE,
|
|
`course_id` BIGINT UNSIGNED NOT NULL,
|
|
`lesson_id` BIGINT UNSIGNED DEFAULT NULL COMMENT 'معرّف الدرس — يكون NULL في امتحانات نهاية الوحدة والامتحانات الشاملة',
|
|
`created_by_id` BIGINT UNSIGNED DEFAULT NULL,
|
|
`creator_type` ENUM('teacher', 'ai_adaptive', 'ministry_standard') NOT NULL DEFAULT 'ai_adaptive',
|
|
`scope` ENUM('in_video_checkpoint', 'lesson_exam', 'unit_exam', 'unit_comprehensive', 'semester_final') NOT NULL DEFAULT 'in_video_checkpoint' COMMENT 'نطاق الامتحان: فحص سقراطي، امتحان درس، أو امتحان وحدة شامل',
|
|
`title` VARCHAR(255) NOT NULL,
|
|
`description` TEXT DEFAULT NULL,
|
|
`duration_minutes` INT UNSIGNED NOT NULL DEFAULT 30,
|
|
`timestamp_seconds` INT UNSIGNED NOT NULL DEFAULT 0 COMMENT 'توقيت ظهور الفحص السقراطي أثناء تشغيل الفيديو',
|
|
`rewind_on_fail_seconds` INT UNSIGNED NOT NULL DEFAULT 45 COMMENT 'عدد الثواني التي يرجع إليها الفيديو عند الخطأ لترسيخ الفهم',
|
|
`passing_percentage` DECIMAL(5, 2) NOT NULL DEFAULT 60.00,
|
|
`total_points` INT UNSIGNED NOT NULL DEFAULT 100,
|
|
`is_mandatory` TINYINT(1) NOT NULL DEFAULT 1,
|
|
`is_published` TINYINT(1) NOT NULL DEFAULT 1,
|
|
`created_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
|
|
`updated_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
|
PRIMARY KEY (`id`),
|
|
KEY `idx_exams_course` (`course_id`),
|
|
KEY `idx_exams_lesson` (`lesson_id`),
|
|
CONSTRAINT `fk_exams_course` FOREIGN KEY (`course_id`) REFERENCES `courses` (`id`) ON DELETE CASCADE,
|
|
CONSTRAINT `fk_exams_lesson` FOREIGN KEY (`lesson_id`) REFERENCES `lessons` (`id`) ON DELETE SET NULL
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- ------------------------------------------------------------------------------
|
|
-- 13. Table: questions (الأسئلة والتحليل المعرفي وهرمية بلوم)
|
|
-- ------------------------------------------------------------------------------
|
|
CREATE TABLE IF NOT EXISTS `questions` (
|
|
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
|
`uuid` CHAR(36) NOT NULL UNIQUE,
|
|
`exam_id` BIGINT UNSIGNED NOT NULL,
|
|
`question_text` TEXT NOT NULL,
|
|
`question_type` ENUM('multiple_choice', 'true_false', 'short_answer') NOT NULL DEFAULT 'multiple_choice',
|
|
`bloom_taxonomy` ENUM('recall', 'comprehension', 'application', 'analysis') NOT NULL DEFAULT 'comprehension' COMMENT 'تصنيف بلوم المعرفي للقياس والتقويم',
|
|
`topic_tag` VARCHAR(150) DEFAULT NULL COMMENT 'الوسم الموضوعي الدقيق للمفهوم العلمي — يُستخدم لمحرك التعليم التكيفي وسد الثغرات',
|
|
`points` INT UNSIGNED NOT NULL DEFAULT 10,
|
|
`explanation_text` TEXT DEFAULT NULL COMMENT 'خطوات الحل والتعليل العلمي النموذجي الموجه للطالب',
|
|
`ai_hint` TEXT DEFAULT NULL COMMENT 'تلميح ذكي يظهر للطالب عند التعثر دون إعطاء الإجابة المباشرة',
|
|
`created_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
|
|
PRIMARY KEY (`id`),
|
|
KEY `idx_questions_exam` (`exam_id`),
|
|
KEY `idx_questions_topic` (`topic_tag`),
|
|
CONSTRAINT `fk_questions_exam` FOREIGN KEY (`exam_id`) REFERENCES `exams` (`id`) ON DELETE CASCADE
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- ------------------------------------------------------------------------------
|
|
-- 14. Table: question_options (خيارات الإجابة والتغذية الراجعة الفورية)
|
|
-- ------------------------------------------------------------------------------
|
|
CREATE TABLE IF NOT EXISTS `question_options` (
|
|
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
|
`question_id` BIGINT UNSIGNED NOT NULL,
|
|
`option_text` TEXT NOT NULL,
|
|
`is_correct` TINYINT(1) NOT NULL DEFAULT 0,
|
|
`feedback_text` TEXT DEFAULT NULL,
|
|
PRIMARY KEY (`id`),
|
|
KEY `idx_options_question` (`question_id`),
|
|
CONSTRAINT `fk_options_question` FOREIGN KEY (`question_id`) REFERENCES `questions` (`id`) ON DELETE CASCADE
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- ------------------------------------------------------------------------------
|
|
-- 15. Table: exam_attempts (محاولات ونتائج الامتحانات وتحليل الفجوات)
|
|
-- ------------------------------------------------------------------------------
|
|
CREATE TABLE IF NOT EXISTS `exam_attempts` (
|
|
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
|
`uuid` CHAR(36) NOT NULL UNIQUE,
|
|
`student_id` BIGINT UNSIGNED NOT NULL,
|
|
`exam_id` BIGINT UNSIGNED NOT NULL,
|
|
`attempt_number` INT UNSIGNED NOT NULL DEFAULT 1,
|
|
`score` DECIMAL(6, 2) NOT NULL DEFAULT 0.00,
|
|
`total_score` DECIMAL(6, 2) NOT NULL DEFAULT 100.00,
|
|
`percentage` DECIMAL(5, 2) NOT NULL DEFAULT 0.00,
|
|
`status` ENUM('passed', 'failed', 'needs_remediation', 'in_progress') NOT NULL DEFAULT 'in_progress',
|
|
`time_spent_seconds` INT UNSIGNED NOT NULL DEFAULT 0,
|
|
`weak_topics_json` JSON DEFAULT NULL COMMENT 'مصفوفة JSON للمفاهيم التي تعثر فيها الطالب لتوجيهه علاجياً',
|
|
`ai_diagnostic_report` TEXT DEFAULT NULL COMMENT 'تقرير التشخيص السقراطي المولد بالذكاء الاصطناعي',
|
|
`completed_at` TIMESTAMP NULL DEFAULT NULL COMMENT 'وقت اكتمال المحاولة — يُستخدم لتتبع جاهزية الطالب وإشعار ولي الأمر',
|
|
`created_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
|
|
PRIMARY KEY (`id`),
|
|
KEY `idx_attempts_student` (`student_id`),
|
|
KEY `idx_attempts_exam` (`exam_id`),
|
|
CONSTRAINT `fk_attempts_student` FOREIGN KEY (`student_id`) REFERENCES `students` (`id`) ON DELETE CASCADE,
|
|
CONSTRAINT `fk_attempts_exam` FOREIGN KEY (`exam_id`) REFERENCES `exams` (`id`) ON DELETE CASCADE
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- ------------------------------------------------------------------------------
|
|
-- 15.5. Table: student_question_answers (تفاصيل إجابات الطالب للتحليل التكيفي)
|
|
-- ------------------------------------------------------------------------------
|
|
CREATE TABLE IF NOT EXISTS `student_question_answers` (
|
|
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
|
`attempt_id` BIGINT UNSIGNED NOT NULL,
|
|
`student_id` BIGINT UNSIGNED NOT NULL,
|
|
`question_id` BIGINT UNSIGNED NOT NULL,
|
|
`selected_option_id` BIGINT UNSIGNED DEFAULT NULL,
|
|
`is_correct` TINYINT(1) NOT NULL DEFAULT 0,
|
|
`points_awarded` DECIMAL(6,2) NOT NULL DEFAULT 0.00,
|
|
`time_spent_seconds` INT UNSIGNED NOT NULL DEFAULT 0,
|
|
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
PRIMARY KEY (`id`),
|
|
KEY `idx_sqa_attempt` (`attempt_id`),
|
|
KEY `idx_sqa_student` (`student_id`),
|
|
KEY `idx_sqa_question` (`question_id`),
|
|
CONSTRAINT `fk_sqa_attempt` FOREIGN KEY (`attempt_id`) REFERENCES `exam_attempts` (`id`) ON DELETE CASCADE,
|
|
CONSTRAINT `fk_sqa_student` FOREIGN KEY (`student_id`) REFERENCES `students` (`id`) ON DELETE CASCADE,
|
|
CONSTRAINT `fk_sqa_question` FOREIGN KEY (`question_id`) REFERENCES `questions` (`id`) ON DELETE CASCADE
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- ------------------------------------------------------------------------------
|
|
-- 15.6. Table: student_error_notebook (دفتر الأخطاء الذكي والمسارات العلاجية التكيفية)
|
|
-- ------------------------------------------------------------------------------
|
|
CREATE TABLE IF NOT EXISTS `student_error_notebook` (
|
|
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
|
`uuid` CHAR(36) NOT NULL UNIQUE,
|
|
`student_id` BIGINT UNSIGNED NOT NULL,
|
|
`subject_id` VARCHAR(100) NOT NULL COMMENT 'المبحث مثل physics_10 أو math_10',
|
|
`subject_name` VARCHAR(255) NOT NULL,
|
|
`topic_name` VARCHAR(255) NOT NULL,
|
|
`lesson_id` BIGINT UNSIGNED DEFAULT NULL,
|
|
`source_type` ENUM('socratic_checkpoint', 'adaptive_exam', 'unit_exam', 'ministry_simulation') NOT NULL DEFAULT 'socratic_checkpoint',
|
|
`question_text` TEXT NOT NULL,
|
|
`options_json` JSON DEFAULT NULL,
|
|
`student_wrong_answer` TEXT NOT NULL,
|
|
`correct_answer` TEXT NOT NULL,
|
|
`socratic_hint` TEXT DEFAULT NULL COMMENT 'شرح سقراطي لسبب الخطأ وكيفية تصحيحه',
|
|
`error_category` ENUM('conceptual', 'calculation', 'rushed', 'misinterpretation') NOT NULL DEFAULT 'conceptual',
|
|
`status` ENUM('pending_remediation', 'in_remediation', 'mastered') NOT NULL DEFAULT 'pending_remediation',
|
|
`remediation_attempts_count` INT UNSIGNED NOT NULL DEFAULT 0,
|
|
`mastered_at` TIMESTAMP NULL DEFAULT NULL,
|
|
`created_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
|
|
PRIMARY KEY (`id`),
|
|
KEY `idx_error_student` (`student_id`),
|
|
KEY `idx_error_subject` (`subject_id`),
|
|
KEY `idx_error_status` (`status`),
|
|
CONSTRAINT `fk_error_student` FOREIGN KEY (`student_id`) REFERENCES `students` (`id`) ON DELETE CASCADE,
|
|
CONSTRAINT `fk_error_lesson` FOREIGN KEY (`lesson_id`) REFERENCES `lessons` (`id`) ON DELETE SET NULL
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- ------------------------------------------------------------------------------
|
|
-- 16. Table: teacher_reviews (تقييمات الطلاب المحصنة بالأوزان وخاصية كشف الكيد)
|
|
-- ------------------------------------------------------------------------------
|
|
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 DEFAULT NULL,
|
|
`lesson_id` BIGINT UNSIGNED DEFAULT 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 DEFAULT 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_tr_teacher` (`teacher_id`),
|
|
KEY `idx_tr_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;
|
|
|
|
-- ------------------------------------------------------------------------------
|
|
-- 17. Table: teacher_performance_metrics (مؤشرات الجدارة التراكمية وطابور الاستجابة العادل)
|
|
-- ------------------------------------------------------------------------------
|
|
CREATE TABLE IF NOT EXISTS `teacher_performance_metrics` (
|
|
`teacher_id` BIGINT UNSIGNED NOT NULL,
|
|
`avg_response_minutes` INT NOT NULL DEFAULT 4,
|
|
`response_rate_percentage` DECIMAL(5, 2) NOT NULL DEFAULT 98.50,
|
|
`active_queue_count` INT UNSIGNED NOT NULL DEFAULT 0,
|
|
`total_students_enrolled` INT UNSIGNED NOT NULL DEFAULT 0,
|
|
`total_reviews_count` INT UNSIGNED NOT NULL DEFAULT 0,
|
|
`raw_avg_rating` DECIMAL(3, 2) NOT NULL DEFAULT 5.00,
|
|
`weighted_student_rating` DECIMAL(3, 2) NOT NULL DEFAULT 5.00,
|
|
`ai_engagement_score` DECIMAL(5, 2) NOT NULL DEFAULT 96.00,
|
|
`sla_speed_score` DECIMAL(5, 2) NOT NULL DEFAULT 98.00,
|
|
`mastery_impact_score` DECIMAL(5, 2) NOT NULL DEFAULT 94.00,
|
|
`composite_merit_score` DECIMAL(5, 2) NOT NULL DEFAULT 96.50,
|
|
`star_equivalent` DECIMAL(3, 2) NOT NULL DEFAULT 4.90,
|
|
`reputation_tier` VARCHAR(100) NOT NULL DEFAULT 'معلم نخبوي معتمد 💎',
|
|
`last_calculated_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
|
PRIMARY KEY (`teacher_id`),
|
|
CONSTRAINT `fk_tpm_teacher` FOREIGN KEY (`teacher_id`) REFERENCES `teachers` (`id`) ON DELETE CASCADE
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- ------------------------------------------------------------------------------
|
|
-- 18. Table: course_access_passes (تصاريح واشتراكات الطلاب: مدرسي مجاني أو ميكرو مخفض)
|
|
-- ------------------------------------------------------------------------------
|
|
CREATE TABLE IF NOT EXISTS `course_access_passes` (
|
|
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
|
`student_id` BIGINT UNSIGNED NOT NULL,
|
|
`course_id` BIGINT UNSIGNED NOT NULL,
|
|
`teacher_id` BIGINT UNSIGNED NOT NULL,
|
|
`pass_type` ENUM('school_included', 'discounted_micro_pass', 'full_marketplace') NOT NULL DEFAULT 'school_included',
|
|
`price_paid_jod` DECIMAL(6, 2) NOT NULL DEFAULT 0.00,
|
|
`expires_at` TIMESTAMP NULL DEFAULT NULL,
|
|
`is_active` TINYINT(1) NOT NULL DEFAULT 1,
|
|
`created_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
|
|
PRIMARY KEY (`id`),
|
|
KEY `idx_cap_student` (`student_id`),
|
|
KEY `idx_cap_course` (`course_id`),
|
|
CONSTRAINT `fk_cap_student` FOREIGN KEY (`student_id`) REFERENCES `students` (`id`) ON DELETE CASCADE,
|
|
CONSTRAINT `fk_cap_course` FOREIGN KEY (`course_id`) REFERENCES `courses` (`id`) ON DELETE CASCADE
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- ------------------------------------------------------------------------------
|
|
-- 19. Table: chat_messages (المحادثات المباشرة بين الطلاب والمعلمين عبر Workerman)
|
|
-- ------------------------------------------------------------------------------
|
|
CREATE TABLE IF NOT EXISTS `chat_messages` (
|
|
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
|
`uuid` CHAR(36) NOT NULL UNIQUE,
|
|
`sender_identity_id` BIGINT UNSIGNED NOT NULL,
|
|
`receiver_identity_id` BIGINT UNSIGNED NOT NULL,
|
|
`course_id` BIGINT UNSIGNED DEFAULT NULL,
|
|
`lesson_id` BIGINT UNSIGNED DEFAULT NULL,
|
|
`message` TEXT NOT NULL,
|
|
`message_type` ENUM('text', 'voice', 'image', 'file') NOT NULL DEFAULT 'text',
|
|
`media_url` VARCHAR(500) DEFAULT NULL,
|
|
`is_read` TINYINT(1) NOT NULL DEFAULT 0,
|
|
`read_at` TIMESTAMP NULL DEFAULT NULL,
|
|
`created_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
|
|
PRIMARY KEY (`id`),
|
|
KEY `idx_chat_identities` (`sender_identity_id`, `receiver_identity_id`),
|
|
KEY `idx_chat_unread` (`receiver_identity_id`, `is_read`),
|
|
CONSTRAINT `fk_chat_sender_id` FOREIGN KEY (`sender_identity_id`) REFERENCES `auth_identities` (`id`) ON DELETE CASCADE,
|
|
CONSTRAINT `fk_chat_receiver_id` FOREIGN KEY (`receiver_identity_id`) REFERENCES `auth_identities` (`id`) ON DELETE CASCADE
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- ------------------------------------------------------------------------------
|
|
-- 20. Table: otp_verifications (رموز التحقق عبر الواتساب وبوابة نبيه)
|
|
-- ------------------------------------------------------------------------------
|
|
CREATE TABLE IF NOT EXISTS `otp_verifications` (
|
|
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
|
`phone_hash` VARCHAR(64) NOT NULL,
|
|
`otp_code_hash` VARCHAR(255) NOT NULL,
|
|
`attempts` INT UNSIGNED NOT NULL DEFAULT 0,
|
|
`is_used` TINYINT(1) NOT NULL DEFAULT 0,
|
|
`expires_at` TIMESTAMP NOT NULL,
|
|
`created_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
|
|
PRIMARY KEY (`id`),
|
|
KEY `idx_otp_phone_hash` (`phone_hash`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
SET FOREIGN_KEY_CHECKS = 1;
|