简体   繁体   English

博客的数据库设计

[英]Database design for blog

I'm looking for the best way to design database for simple blog. 我正在寻找为简单博客设计数据库的最佳方法。 My idea is: 我的想法是:

  • Posts table - contains id, content, etc., 帖子表-包含ID,内容等,
  • Categories - contains category id, name, link-name (simple name used for example in routes), 类别-包含类别ID,名称,链接名称(例如在路线中使用的简单名称),
  • Tags - tag id, tag name, link-name, 标签-标签ID,标签名称,链接名称,
  • CategoriesMap - contains post id and category id, post may have a few categories, CategoriesMap-包含帖子ID和类别ID,帖子可能包含一些类别,
  • TagMap - as above. TagMap-如上所述。

Is it good solution? 这是好的解决方案吗? I use Symfony3 with Doctrine and MySQL. 我将Symfony3与Doctrine和MySQL一起使用。

In addition to the tables above, I recommend you add the following tables: 除了上面的表格,我建议您添加以下表格:

  1. staff: a table for staff which may include fields like: id, name, role (Author, Editor, etc), email, password, photo etc. Then add the staff id on the Posts table. 职员:职员表,其中可能包括ID,名称,角色(作者,编辑者等),电子邮件,密码,照片等字段。然后在“职位”表上添加职员ID。
  2. visitor: a table of visitors is not a bad idea either. 访客:访客表也不是一个坏主意。 It have have fields like visitor id, name(null=YES), email(null=YES), subscription(YES/NO/NULL), ip_address(null=YES), favorite_category(null=YES) etc. 它具有诸如访客ID,名称(null = YES),电子邮件(null = YES),订阅(YES / NO / NULL),ip_address(null = YES),favourite_category(null = YES)等字段。
  3. comment: In addition, you may want to have a comment table where you have fields like: id, message, visitor_id, post_id etc. comment:此外,您可能需要一个注释表,其中包含以下字段:id,消息,visitor_id,post_id等。

A user table should be there to track the post authors and to implement a login/registration system. 应该有一个用户表来跟踪帖子作者并实现登录/注册系统。 The same table can be used to securely manage the blog posts. 同一张表可用于安全地管理博客文章。

Also, comment system is an integral part of a blogging system. 同样,评论系统是博客系统的组成部分。 You can either have a table to store comments or integrate an external commenting system. 您可以有一个表来存储评论,也可以集成一个外部评论系统。

You can also check this ER Diagram to have more clarity about what I am saying. 您也可以查看此ER图,以更清楚地了解我在说什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM