A
A
Alexander Evgenievich2015-04-03 16:30:03
MySQL
Alexander Evgenievich, 2015-04-03 16:30:03

How to design a database to work with notifications?

Hello.
There is a task to make a notification system. The directions in which notifications will work are many. Here, as well as notification of the addition of new posts, orders, comments, and system notifications. For example, when adding a response to a comment, both the owner of the comment and the owner of the post under which the comment was posted should be notified.
The thought comes to mind to store notifications as follows:
|-----Notifications-----|
=================
| id----------------------|
| user_id ---------------| - this is from whom the notification
| subscriber_id -------| - this is FOR whom the notice
| type ------------------| - this is a string with the name of the notification TYPE (_comment, _post, _hire, _answer, etc.)
| resource_id ---------| is a pointer to the entity that is bound to the notification
| created_at----------|
| is_active ------------| - mark if read
================
I also thought of adding fields to save information (title, description) .
Basically the question is in the title. Maybe someone has already solved similar problems and can share their experience. Again, I considered options with a clear connection, i.e. adding fields to the table - comment_id, post_id, etc.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex, 2015-04-03
@banderos120

Separate tables for each notification type are not considered?
Your entities will be different, what type for resource_id will you choose? Bigint must be taken :)
You can have a common table of notifications (notifications) for the convenience of sampling, in which, among other things, there will be a pair of FK fields (notification_type + notification_id) and each type has its own table (comment_notifications, like_notifications) with any sets of fields required for each type .
Well, this is so, the first thought aloud.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question