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

时间:2014-02-04 20:16:49

标签: mysql database database-design database-schema

我正在为网络应用构建一个通用的通知系统。我使用的主要技术是 Java,Spring MVC和Hibernate 。我一直在寻找几个帖子,试图找到最适合我的解决方案,考虑推荐的做法。

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

这是我的代码:

通知示例:

@user addedcomment

用户[USER_ID] [USER_ACTION][OBJECT]


>>>更新>>>

[14年5月2日]

  • id_recipient表格中移除了seennotification字段。 (@Kombajnzbożowy)
  • 创建了新表notification_user。 (@Kombajnzboż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;

notification_user:,以便可以向多个收件人(用户)发送一个通知。

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;

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;

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;     

0 个答案:

没有答案