kudlajz
kudlajz

Reputation: 1066

Flag messages as deleted for one user in conversation

I have a database schema like this:

conversation
    - id
    - created

user_has_conversation
    - user_id
    - conversation_id

message
    - id
    - user_id
    - conversation_id
    - text

How can I design these tables if one user decides to delete the conversation or some messages, but I want them to remain visible for the other user.

Should I create a new table called

message_deleted
    - user_id
    - message_id

And fill it with IDs of deleted messages?

Upvotes: 1

Views: 118

Answers (2)

philipxy
philipxy

Reputation: 15158

Yes, you should use a table like you suggested:

message_deleted
    - user_id
    - message_id

Your "being deleted" is a many-to-many relationship on user_id and message_id.

if one user decides to delete the conversation or some messages, but I want them to remain visible for the other user.

Similarly you would have a table for conversations:

conversation_deleted
    - user_id
    - conversation_id

Upvotes: 1

user821445
user821445

Reputation:

You can simply add a flag 'visible' (default true) to the message table.

Upvotes: 0

Related Questions