Improving Database Design for MySQL Notification System

I am in the process of creating a common notification system for a web application . The main technologies that I use are Java, Spring MVC and Hibernate . I looked through several posts here and there, trying to find the solution that suits me best, taking into account the recommended practices.

I have coded your database table and would like to get some feedback feedback to improve my design to avoid big changes in my Java implementation classes. My goal is to make it as complete, scalable and optimal as possible while keeping complexity to a minimum.

Here is my code:

SAMPLE NOTIFICATIONS:

@user addednew one comment.

The user is [USER_ID] [USER_ACTION]new [OBJECT].


>>> Updates >>>

[05/02/14]

  • Fields id_recipientand seenremoved from the table notification. (@Kombajn zbożowy)
  • A new table has been created notification_user. (@Kombajn zbożowy)
  • String identifiers. (@Wildplasser)

notification

CREATE TABLE notification (
           id_notification BIGINT(20) NOT NULL AUTO_INCREMENT,   
           id_notification_type BIGINT(20) NOT NULL,
           id_action_type BIGINT(20) NOT NULL,
           id_sender BIGINT(20) NOT NULL,           
           created_date TIMESTAMP NOT NULL,
           url VARCHAR(300) NULL,       

           PRIMARY KEY (id_notification),
           FOREIGN KEY (id_notification_type) REFERENCES notification _type (id_notification_type),
           FOREIGN KEY (id_action_type) REFERENCES action_type (id_action_type),
           FOREIGN KEY (id_sender) REFERENCES user (id_user)      

    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

messages_user: so that one notification can be sent to several recipients (users).

CREATE TABLE notification_user (
           id_notification BIGINT(20) NOT NULL,
           id_recipient BIGINT(20) NOT NULL,
           seen TINYINT(1) DEFAULT 0,   

           PRIMARY KEY (id_notification , id_recipient),
           FOREIGN KEY (id_notification) REFERENCES notification (id_notification),
           FOREIGN KEY (id_recipient) REFERENCES user (id_user)

    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

messages_type : refers to the type of object that has been modified by the actions of a specific user. Example: comment, post, etc.

CREATE TABLE notification_type (
               id_notification_type BIGINT(20) NOT NULL AUTO_INCREMENT,   
               notification_name VARCHAR(100) NOT NULL,
               description VARCHAR(300) NULL,

               PRIMARY KEY (id_notification_type)   

) ENGINE=InnoDB DEFAULT CHARSET=utf8;

action_type : actions performed by users who trigger notifications. Usually: update, add, delete, etc.

 CREATE TABLE action_type (
           id_action_type BIGINT(20) NOT NULL AUTO_INCREMENT,   
           action_name VARCHAR(100) NOT NULL,     

           PRIMARY KEY (id_action_type) 
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+4
source

All Articles