E
E
Egor Astreiko2019-04-20 14:54:00
Database design
Egor Astreiko, 2019-04-20 14:54:00

How to create a table structure in a chat database?

Hello everyone, I need help creating a table structure for a chat, I need a chat like in VK.
1) There can be more than two participants
2) You can edit only your own messages (while the source of the old one was saved)
3) You can delete your message from all interlocutors, someone else's only from yourself (while the source of the message is saved)
4) You can send files
5) You can reply to messages (as in VK, you select a message, press reply, after which you write a message and when this message is delivered, the forwarded message is a link and highlights the original message in the dialog) (you can send as many messages as you like at a time)

Here are my efforts
5cbb018ce6e29064112505.png
  • Blue highlighted keys to which they refer
  • Highlighted in red keys, from which they refer

Tables:
Table_chat_type - Chat type
Table_chat - Table of the chat itself
Table_chat_user - List of users in all created chats
Table_chat_message - Message
Table_chat_message_content - Message content
Table_chat_message_file - Files that were sent in the message
Table_chat_message_text - Text that was sent in the message
Table_message_status - Message status, which user answered read the message, which one is not
The problem is this:
1) I don’t know if this structure is correct at all, since I want to achieve the most approximate version, as in VKontakte, and so that there is as little load as possible and a high return speed of all this with a large number of chats.
2) I don't know how to make it possible to reply to a message like in a contact
. Thank you in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
TheRonCronix, 2019-04-20
@TheRonCronix

1 Start by highlighting entities:
user
message
conversation
etc.
2 Draw a logical database diagram: entities and relationships between them (one-to-many, many-to-many, many-to-one). For example, one user can have many conversations.
3. Add attributes from the entity. For example, for a message, this is the date the message was sent, the date it was read, the sign of deletion/editing, etc.
4. Define keys and constraints.
4. Create a physical database. Many-to-many relationships are designed by a bridge table. Add the desired indexes, constraints, storage options for table data, partitioning, clustering, and so on.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question