改进 MySQL 通知系统的数据库设计

Cou*_*ntD 5 mysql database database-design database-schema

我正在为 webapp构建通用通知系统。我使用的主要技术是Java、Spring MVC 和 Hibernate。我一直在这里和那里查看几篇文章,试图提出最适合我的解决方案,同时考虑到推荐的做法。

我已经对我的数据库表进行了编码,并希望收到一些反馈,以 改进我的设计以避免在我实现 Java 类时发生大的变化。我的目标是使其尽可能完整、可扩展和优化,同时将复杂性降至最低。

这是我的代码:

通知示例:

@user added一个新的comment

用户[USER_ID] [USER_ACTION]一个新的[OBJECT].


>>> 更新 >>>

[05/02/14]

  • 字段id_recipientseennotification表中删除。(@Kombajn zbo?owy)
  • 新表已notification_user创建。(@Kombajn zbo?owy)
  • 小写标识符。(@wildplasser)

通知

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;
Run Code Online (Sandbox Code Playgroud)

通知用户:这样一个通知可以发送给多个收件人(用户)。

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;
Run Code Online (Sandbox Code Playgroud)

notification_type:指的是由某个用户的操作修改的对象类型。例如:评论、发帖等。

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;
Run Code Online (Sandbox Code Playgroud)

action_type:触发​​通知的用户执行的操作。通常:更新、添加、删除等。

 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;
Run Code Online (Sandbox Code Playgroud)