feat: Full API-driven Student-Teacher Chat architecture with chat_messages table and endpoints

This commit is contained in:
Hamza-Ayed
2026-08-27 00:05:30 +03:00
parent 1d78fe8cc1
commit 12f00a05b6
3 changed files with 353 additions and 1 deletions
+30 -1
View File
@@ -8,7 +8,7 @@ SET FOREIGN_KEY_CHECKS = 0;
-- ------------------------------------------------------------------------------
-- DROP ALL EXISTING TABLES IN REVERSE ORDER TO PREVENT FOREIGN KEY CONFLICTS
-- ------------------------------------------------------------------------------
DROP TABLE IF EXISTS `chat_messages`;
DROP TABLE IF EXISTS `otp_verifications`;
DROP TABLE IF EXISTS `user_devices`;
DROP TABLE IF EXISTS `voice_notes`;
@@ -273,4 +273,33 @@ CREATE TABLE `otp_verifications` (
KEY `idx_otp_phone_hash` (`phone_hash`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- ------------------------------------------------------------------------------
-- 15. Table: chat_messages (المحادثات المباشرة بين الطلاب والمعلمين)
-- ------------------------------------------------------------------------------
CREATE TABLE `chat_messages` (
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
`uuid` CHAR(36) NOT NULL,
`sender_id` BIGINT UNSIGNED NOT NULL,
`receiver_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,
`updated_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
UNIQUE KEY `idx_chat_messages_uuid` (`uuid`),
KEY `idx_chat_sender_receiver` (`sender_id`, `receiver_id`),
KEY `idx_chat_receiver_unread` (`receiver_id`, `is_read`),
KEY `idx_chat_course` (`course_id`),
KEY `idx_chat_created_at` (`created_at`),
CONSTRAINT `fk_chat_sender` FOREIGN KEY (`sender_id`) REFERENCES `users` (`id`) ON DELETE CASCADE,
CONSTRAINT `fk_chat_receiver` FOREIGN KEY (`receiver_id`) REFERENCES `users` (`id`) ON DELETE CASCADE,
CONSTRAINT `fk_chat_course` FOREIGN KEY (`course_id`) REFERENCES `courses` (`id`) ON DELETE SET NULL,
CONSTRAINT `fk_chat_lesson` FOREIGN KEY (`lesson_id`) REFERENCES `lessons` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
SET FOREIGN_KEY_CHECKS = 1;