APPLE199's avatar

Best database structure to create a messaging system?

So I'm trying to create a messaging system (have been trying for 2 days non stop) and haven't found THE best database structure to use. I am thinking of creating a "threaded" system; like Gmail's -- it's got inbox, sent, deleted, etc.

I have thought of this schema, please let me know if you have a better one.

threads: id, subject, user_id

messages: id, user_id, body

message_user (pivot): id, user_id, message_id, deleted_at, read_at

How does this sound?

0 likes
4 replies
dawiyo's avatar

I've been working on one too recently and pretty much had the exact same structure. I didn't have deleted_at on the pivot though. Do you think that is that really needed?

Nick12345's avatar

....Come to think of it.....I wonder how this commenting system is set up...seems to have heirachy set up with these replies. Seems like you could analyse it and work out a similar structure.

Please or to participate in this conversation.