CREATE TABLE IF NOT EXISTS `messages` ( `id` int NOT NULL AUTO_INCREMENT, `organizationId` int NOT NULL, `sender_id` int NOT NULL, `receiver_id` int NOT NULL, `message` text NOT NULL, `timestamp` datetime DEFAULT CURRENT_TIMESTAMP, `is_file` tinyint(1) DEFAULT '0', `filename` varchar(255) DEFAULT NULL, `is_read` tinyint(1) DEFAULT '0', `reply_to_id` int DEFAULT NULL, PRIMARY KEY (`id`), KEY `sender_id` (`sender_id`), KEY `receiver_id` (`receiver_id`), KEY `fk_messages_org` (`organizationId`), CONSTRAINT `fk_messages_org` FOREIGN KEY (`organizationId`) REFERENCES `organizations` (`id`) ON DELETE CASCADE, CONSTRAINT `fk_messages_receiver` FOREIGN KEY (`receiver_id`) REFERENCES `users` (`id`) ON DELETE CASCADE, CONSTRAINT `fk_messages_sender` FOREIGN KEY (`sender_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ) CREATE TABLE IF NOT EXISTS `project_room_messages` ( `id` int NOT NULL AUTO_INCREMENT, `organizationId` int NOT NULL, `projectId` int NOT NULL, `roomId` int NOT NULL, `sender_id` int NOT NULL, `message` text COLLATE utf8mb4_unicode_ci NOT NULL, `timestamp` datetime DEFAULT CURRENT_TIMESTAMP, `is_file` tinyint(1) DEFAULT '0', `filename` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `is_read` tinyint(1) DEFAULT '0', `reply_to_id` int DEFAULT NULL, PRIMARY KEY (`id`), KEY `idx_room` (`organizationId`,`projectId`,`roomId`), KEY `idx_sender` (`sender_id`), CONSTRAINT `fk_prm_org` FOREIGN KEY (`organizationId`) REFERENCES `organizations` (`id`) ON DELETE CASCADE, CONSTRAINT `fk_prm_sender` FOREIGN KEY (`sender_id`) REFERENCES `users` (`id`) ON DELETE CASCADE )