Search code examples
mysqlmessage

Personal/Group messaging schema


How to create message conversation schema in MySQL both personal group messaging. Is there a possibility to create with following scenario.

  1. read/unread
  2. If user delete conversation does not affect other.(For example user A & B has message conversation A clears Message then B messages should not affect)

Solution

  • How about this:

    MessageGroup (
        ID, 
        GroupName
    )
    
    Message (
        ID, 
        Text, 
        MessageGroupId (FK TO MessageGroup(ID))
    )
    
    User (
        ID, 
        UserName
    )
    
    UserMessage (
        ID, 
        MessageID (FK to Message(ID)), 
        UserID (FK to User(ID), 
        Cleared (true/false)
    )
    

    This way, each user can clear the message but only for him, while others can still have their messages unaffected.