Database Design for storing Chat Messages between people

前端 未结 3 779
失恋的感觉
失恋的感觉 2021-02-01 20:37

I am trying to build a messaging/chat system. which can store conversation between two people in a chronological order. Also if User A deletes the conversation User B still shou

3条回答
  •  南笙
    南笙 (楼主)
    2021-02-01 20:56

    There will be two tables. nodes node_user

    In nodes table,

    • node_id
    • title
    • message
    • timestamp

    In node_user table,

    • node_user_id(PK)
    • node_id
    • parent_node_id(for threaded)
    • from_id
    • to_id
    • timestamp
    • read

    When user A send a message to user B, firstly store the message in nodes table. And then, add two records in node_user table. When user A delete the message, only delete the first record in node_user table. When user B delete the message, you can delete records from both nodes and node_user table.

    Threaded Message,

    • Use parent_node_id

提交回复
热议问题