Help design a database for posting messages.
- It should be possible to store messages in a hierarchy, i.e. the user can create folders and move messages there. For storage of hierarchical data selected
Nested Set.
Question: How to associate messages with folders to store them. Now I have created the MessageCatalogs table. It turns out something like the following:
+-------------+----------------------+-----+-----+----------------------+ | id | name | lft | rgt | messageId | +-------------+----------------------+-----+-----+----------------------+ | 1 | Входящие | 1 | 10| NULL | | 2 | NULL | 2 | 3 | 1 | | 3 | NULL | 4 | 5 | 2 | | 4 | Исходящие | 10| 15| NULL | | 5 | NULL | 11| 12| 5 | | 6 | NULL | 13| 14| 8 | | 4 | Тех(внутри Входящ.) | 6 | 9 | NULL | | 5 | NULL | 7 | 8 | 10 | Maybe you need to combine MessageCatalogs and UserMessage into 1 table?
UPD
- 1 message can be sent to multiple users at once.
- Each user has their own set of folders

Nested Setis a specialized structure for storing hierarchical data and treatments specific to this type of data . And you have such treatments until the emphasis can be seen ... - Akina