扩展数据库以进行组/协作消息传递

时间:2017-09-12 08:33:38

标签: mysql database database-design chat messaging

我正在创建我正在创建的消息传递应用程序的数据库架构: -

表名: - conversation_threads

+-----------------+-------+---------+
| conversation_id | label | members |
+-----------------+-------+---------+
| 1               | TEST  | 1,2     |
+-----------------+-------+---------+
| 2               | XYZ   | 4,1     |
+-----------------+-------+---------+

表名: - messages

+------------+----------------+-----------+-----------------+---------------------+
| message_id | message        | sender_id | conversation_id | created_at          |
+------------+----------------+-----------+-----------------+---------------------+
| 1          | Hello          | 1         | 1               | 2017-09-12 09:00:00 |
+------------+----------------+-----------+-----------------+---------------------+
| 2          | Hi             | 2         | 1               | 2017-09-12 09:02:00 |
+------------+----------------+-----------+-----------------+---------------------+
| 3          | Hey!           | 4         | 2               | 2017-09-12 08:16:00 |
+------------+----------------+-----------+-----------------+---------------------+

表名: - message_users

+----------+-------------+---------+--------+
| mu_id    | message_id  | user_id | status |
+----------+-------------+---------+--------+
| 1        | 1           | 1       | READ   |
+----------+-------------+---------+--------+
| 2        | 1           | 2       | UNREAD |
+----------+-------------+---------+--------+
| 3        | 2           | 2       | READ   |
+----------+-------------+---------+--------+
| 4        | 2           | 1       | UNREAD |
+----------+-------------+---------+--------+
| 5        | 3           | 4       | READ   |
+----------+-------------+---------+--------+
| 6        | 3           | 1       | UNREAD |
+----------+-------------+---------+--------+

这种架构在一对一消息传递中运行良好。

但现在我想在一个对话中介绍两个以上的用户,以便所有3或4个或更多人可以协作和讨论事情。

我面临的问题是,如果我在会话线程中的members字段中添加另一个用户 - 他可以访问从一开始就读取该特定会话线程中存在的所有消息 - 尽管他被添加到了晚期进入对话。

请为我提供解决方案,解决这个问题。

希望我的问题不是太广泛。

1 个答案:

答案 0 :(得分:0)

如果我理解你的架构关系,你只需要像你那样放置成员

+-----------------+-------+---------+
| conversation_id | label | members |
+-----------------+-------+---------+
| 1               | TEST  | 1,2,3,4 |
+-----------------+-------+---------+