User message database schema?

This is probably very subjective, and I have my thoughts on this, but how would I build a database design that supports user messages (from one to one or from one to many).

My initial thought was to have a MESSAGE table and a MESSAGE_PARTIES table

The MESSAGE will include the following fields: -ID, Subject, Body, Created, Parent MSG ID (for replies)

Fields

MESSAGES include: -ID, message identifier, sender identifier, recipient identifier, sent to

Is this sound logic? I am dying to find out which is better / more efficient.

+4
source share
1 answer

You are not quite right with MESSAGE PARTIES . Given the current setting, you can specify several senders and several dates (more precisely, you can specify several combinations of sender, recipient and date). This is not like any messaging system I am familiar with, and most likely not what you intended (it also doesn't fit your description).

A more appropriate layout places the sender and "sent" fields in the MESSAGE table, and then just the ID , Message ID and Recipient ID in the MESSAGE PARTIES table.

+9
source

Source: https://habr.com/ru/post/1316002/


All Articles