M
M
Maxim2019-07-25 16:05:33
MySQL
Maxim, 2019-07-25 16:05:33

How to store User Settings?

Hello. It is necessary to implement Profile settings, notifications, other sections, and so on. For example, how the settings section on Toster is implemented for each user. The question arises - how to store this data? Someone advises in the user table, and if there is a lot of data, then in json format of one field of this table. Someone advises to put it in a separate settings table and add the necessary settings roles in it. Someone suggests storing in a separate table, but in the format of a field, value.
Duck all the same, how should you store the Settings?) There is one section on the toaster called "Notification Settings". It's interesting how it's implemented. Despite the fact that there are two options: notify by mail, notify on the site. How is it done correctly?)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
orbit070, 2019-07-25
@myks92

It is impossible to give a definite answer to the question. All of the above methods have the right to life in certain situations, but:
1) I would not advise you to litter the user table unnecessarily, you will get a huge mess.
2) I would recommend Json only in an exceptional case, after all, this is a departure from normal forms.
3) The most canonical is to put the settings in a separate table like user_settings(user_id, setting1, setting2, ...).
Regarding notifications - since notifications are more often a set, each individual notification can, of course, be entered into the settings table and conveniently, but not quite frankly. If there are not so many notification items, then you can enter them directly into the settings table, that is, like this user_settings(user_id, setting1, setting2, ..., notification1, notification2, ...). But this option is not flexible, because, for example, each individual notification may require further settings (for example, notification priority). Therefore, it would be most correct to have one table for profile settings as indicated above, and a second table for notifications of the form user_notifications(user_id, notification_id, notification_name, priority, ...). So everything will be very flexible and will correspond to normal forms.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question