S
S
Sergey2019-04-12 11:54:13
MySQL
Sergey, 2019-04-12 11:54:13

Is there a universal DB structure for messaging?

For the purpose of self-study, I rivet my bike in PHP.
Now I'm implementing the messaging functionality.
I want to create a more or less universal database structure (in MYSQL for a start) for different types of correspondence: dialogs, chats, groups, comments on articles, etc.
After reading various tips and examples, I threw in such a database structure.
5cb04c303ad62073382143.png
The number of tables may seem redundant, but my goal is the most versatile structure for any possible extension of functionality without the need to change the structure of the database.
Briefly on the tables:
1. users - a list of users
2. chats - a list of all chats with an indication of the type (dialog, chat, comments, etc.)
3. chatprop - chat property (title, picture, pinned message, ability to like messages, etc.)
4. chatmembers - chat members. Status: admin, member, reader, left the chat, etc.
5. messages - a list of messages indicating the chat, author and date of creation
6. messagecontent - the content of the message (text, pictures, files, links, polls, etc.), there can be several attachments per message, so I put it in a separate table , although in a simple case it can be combined with the messages table. Here you can also add likes-dislikes to messages
7. messagetouser - Binding messages to users indicating readability and deletion from history. Messages are included here depending on the type of chat, for example, comments on articles/posts are not added here.
The most loaded last 3 tables, with a possible increase in load, it is possible to provide for the separation of these tables on different servers or the splitting of all three with the separation of the most active chats on different servers.
Any advice on how to improve/optimize the database structure?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lexxtor, 2019-04-12
@Lexxtor

I agree with mindtester.
And bad naming. All table names must be written in the singular and without abbreviations (user, chat_property, etc.). Instead of chatmessage_id, you need message_id - this will make it clearer that this is a link to the id field in the message table.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question