当前位置:网站首页>论坛系统数据库设计
论坛系统数据库设计
2022-04-23 11:24:00 【BreezAm】
论坛系统数据库设计
数据库SQL文件已被收录于Gitee: 论坛系统数据库设计资源下载
文章目录
前言
数据库设计尤为重要,因为他是后面系统开发的基石,义务和数据库是分不开的。
一、社区论坛是什么?

1、社区论坛是一个网络板块,指不同的人围绕同一主题引发的讨论,如天涯社区。类似的名词还有论坛、贴吧等。同时也是指固定的地理区域范围内的社会成员以居住环境为主体,行使社会功能、创造社会规范物,与行政村同一等级的行政区域。
2、社区,最具活力的社区是互联网最具知名度的综合性社区,拥有庞大核心用户群体,社区主题涵盖女性、娱乐、汽车、体育、文化、生活、社会、时事、历史、文学、情感、旅游、星座等各项领域。
二、设计表
1.用户表
用户表 重要字段:
用户ID、用户名、密码、关注我的人数、我关注的人数、我关注的文章数、我关注的问题数、我关注的话题数、我发表的文章数量、我发表的问题数量、我发表的回答数量、未读通知数、未读私信数


CREATE TABLE `mc_user` (
`user_id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '用户ID',
`username` varchar(20) NOT NULL COMMENT '用户名',
`email` varchar(320) NOT NULL COMMENT '邮箱',
`avatar` varchar(50) DEFAULT NULL COMMENT '头像token',
`cover` varchar(50) DEFAULT NULL COMMENT '封面图片token',
`password` varchar(255) NOT NULL COMMENT '密码',
`create_ip` varchar(80) DEFAULT NULL COMMENT '注册IP',
`create_location` varchar(100) DEFAULT NULL COMMENT '注册地址',
`last_login_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '最后登录时间',
`last_login_ip` varchar(80) DEFAULT NULL COMMENT '最后登陆IP',
`last_login_location` varchar(100) DEFAULT NULL COMMENT '最后登录地址',
`follower_count` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '关注我的人数',
`followee_count` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '我关注的人数',
`following_article_count` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '我关注的文章数',
`following_question_count` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '我关注的问题数',
`following_topic_count` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '我关注的话题数',
`article_count` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '我发表的文章数量',
`question_count` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '我发表的问题数量',
`answer_count` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '我发表的回答数量',
`notification_unread` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '未读通知数',
`inbox_unread` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '未读私信数',
`headline` varchar(40) DEFAULT NULL COMMENT '一句话介绍',
`bio` varchar(160) DEFAULT NULL COMMENT '个人简介',
`blog` varchar(255) DEFAULT NULL COMMENT '个人主页',
`company` varchar(255) DEFAULT NULL COMMENT '公司名称',
`location` varchar(255) DEFAULT NULL COMMENT '地址',
`create_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '注册时间',
`update_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '更新时间',
`disable_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '禁用时间',
PRIMARY KEY (`user_id`),
KEY `user_name` (`username`),
KEY `email` (`email`),
KEY `follower_count` (`follower_count`),
KEY `create_time` (`create_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户表';
2.Token表
token表用来保存登录用户的登录信息,有一个过期过期时间。一般都把用户的
token保存到redis,设置过期时间自动删除对应的key。
重要字段:token字符串、用户ID、过期时间

CREATE TABLE `mc_token` (
`token` varchar(50) NOT NULL DEFAULT '' COMMENT 'token 字符串',
`user_id` int(11) unsigned NOT NULL COMMENT '用户ID',
`device` varchar(600) NOT NULL DEFAULT '' COMMENT '登陆设备,浏览器 UA 等信息',
`create_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '创建时间',
`update_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '更新时间',
`expire_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '过期时间',
PRIMARY KEY (`token`),
KEY `user_id` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户TOKEN';
3. 文章表
文章表 重要字段:用户ID、
评论数量、关注者数量、投票数、赞成票数、反对票数

CREATE TABLE `mc_article` (
`article_id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '文章ID',
`user_id` int(11) unsigned NOT NULL COMMENT '用户ID',
`title` varchar(80) NOT NULL COMMENT '标题',
`content_markdown` text COMMENT '原始的正文内容',
`content_rendered` text COMMENT '过滤渲染后的正文内容',
`comment_count` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '评论数量',
`follower_count` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '关注者数量',
`vote_count` int(11) NOT NULL DEFAULT '0' COMMENT '投票数,赞成票-反对票,可以为负数',
`vote_up_count` int(11) NOT NULL DEFAULT '0' COMMENT '赞成票总数',
`vote_down_count` int(11) NOT NULL DEFAULT '0' COMMENT '反对票总数',
`create_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '创建时间',
`update_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '更新时间',
`delete_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '删除时间',
PRIMARY KEY (`article_id`),
KEY `user_id` (`user_id`),
KEY `create_time` (`create_time`),
KEY `vote_count` (`vote_count`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='文章表';
4. 话题表
话题表 重要字段:
话题名称、话题描述、文章数量、问题数量、关注者数量

CREATE TABLE `mc_topic` (
`topic_id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '话题ID',
`name` varchar(20) NOT NULL DEFAULT '' COMMENT '话题名称',
`cover` varchar(50) DEFAULT NULL COMMENT '封面图片token',
`description` varchar(1000) NOT NULL DEFAULT '' COMMENT '话题描述',
`article_count` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '文章数量',
`question_count` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '问题数量',
`follower_count` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '关注者数量',
`delete_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '删除时间',
PRIMARY KEY (`topic_id`),
KEY `name` (`name`),
KEY `follower_count` (`follower_count`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='话题表';
5. 问题表
问题表 重要字段:
用户ID、标题、内容、评论数量、回答数量、关注者数量、投票数、赞成票数、反对票数

CREATE TABLE `mc_question` (
`question_id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '问题ID',
`user_id` int(11) unsigned NOT NULL COMMENT '用户ID',
`title` varchar(80) NOT NULL COMMENT '标题',
`content_markdown` text COMMENT '原始的正文内容',
`content_rendered` text COMMENT '过滤渲染后的正文内容',
`comment_count` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '评论数量',
`answer_count` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '回答数量',
`follower_count` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '关注者数量',
`vote_count` int(11) NOT NULL DEFAULT '0' COMMENT '投票数,赞成票-反对票,可以为负数',
`vote_up_count` int(11) NOT NULL DEFAULT '0' COMMENT '赞成票总数',
`vote_down_count` int(11) NOT NULL DEFAULT '0' COMMENT '反对票总数',
`last_answer_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '最后回答时间',
`create_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '创建时间',
`update_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '更新时间',
`delete_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '删除时间',
PRIMARY KEY (`question_id`),
KEY `user_id` (`user_id`),
KEY `create_time` (`create_time`),
KEY `update_time` (`update_time`),
KEY `vote_count` (`vote_count`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='问题表';
6. 评论表
评论表 重要字段:
评论目标ID、用户ID、回复数量、投票数、反对票数、赞成票数、评论的内容

CREATE TABLE `mc_comment` (
`comment_id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '回答评论ID',
`commentable_id` int(11) unsigned NOT NULL COMMENT '评论目标的ID',
`commentable_type` char(10) NOT NULL COMMENT '评论目标类型:article、question、answer、comment',
`user_id` int(11) unsigned NOT NULL COMMENT '用户ID',
`content` text NOT NULL COMMENT '原始正文内容',
`reply_count` int(11) NOT NULL DEFAULT '0' COMMENT '回复数量',
`vote_count` int(11) NOT NULL DEFAULT '0' COMMENT '投票数,赞成票-反对票,可以为负数',
`vote_up_count` int(11) NOT NULL DEFAULT '0' COMMENT '赞成票总数',
`vote_down_count` int(11) NOT NULL DEFAULT '0' COMMENT '反对票总数',
`create_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '创建时间',
`update_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '更新时间',
`delete_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '删除时间',
PRIMARY KEY (`comment_id`),
KEY `user_id` (`user_id`),
KEY `commentable_id` (`commentable_id`),
KEY `create_time` (`create_time`),
KEY `vote_count` (`vote_count`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='回答评论表';
7. 投票表
投票表 重要字段:
用户ID、投票目标ID、投票类型(赞成还是反对)、投票类型

CREATE TABLE `mc_vote` (
`user_id` int(11) unsigned NOT NULL COMMENT '用户ID',
`votable_id` int(11) unsigned NOT NULL COMMENT '投票目标ID',
`votable_type` char(10) NOT NULL COMMENT '投票目标类型 question、answer、article、comment',
`type` char(10) NOT NULL COMMENT '投票类型 up、down',
`create_time` int(10) unsigned NOT NULL COMMENT '投票时间',
KEY `user_id` (`user_id`),
KEY `voteable_id` (`votable_id`),
KEY `create_time` (`create_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
8. 回答表
回答表 重要字段:
问题ID、用户ID、回答的内容、评论数量、投票数、赞成票数、反对票数

CREATE TABLE `mc_answer` (
`answer_id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '回答ID',
`question_id` int(11) unsigned NOT NULL COMMENT '问题ID',
`user_id` int(11) unsigned NOT NULL COMMENT '用户ID',
`content_markdown` text NOT NULL COMMENT '原始的正文内容',
`content_rendered` text NOT NULL COMMENT '过滤渲染后的正文内容',
`comment_count` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '评论数量',
`vote_count` int(11) NOT NULL DEFAULT '0' COMMENT '投票数,赞成票-反对票,可以为负数',
`vote_up_count` int(11) NOT NULL DEFAULT '0' COMMENT '赞成票总数',
`vote_down_count` int(11) NOT NULL DEFAULT '0' COMMENT '反对票总数',
`create_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '创建时间',
`update_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '更新时间',
`delete_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '删除时间',
PRIMARY KEY (`answer_id`),
KEY `question_id` (`question_id`),
KEY `user_id` (`user_id`),
KEY `vote_count` (`vote_count`),
KEY `create_time` (`create_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='回答表';
9. 举报表
举报表 重要字段:
举报目标ID、用户ID、举报目标类型、举报原因

CREATE TABLE `mc_report` (
`report_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`reportable_id` int(11) unsigned NOT NULL COMMENT '举报目标ID',
`reportable_type` char(10) NOT NULL COMMENT '举报目标类型:question、article、answer、comment、user',
`user_id` int(11) unsigned NOT NULL COMMENT '用户ID',
`reason` varchar(200) NOT NULL COMMENT '举报原因',
`create_time` int(11) unsigned NOT NULL COMMENT '举报时间',
PRIMARY KEY (`report_id`),
KEY `reportable_id` (`reportable_id`),
KEY `reportable_type` (`reportable_type`),
KEY `create_time` (`create_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='举报';
10. 话题关系对应表

CREATE TABLE `mc_topicable` (
`topic_id` int(11) unsigned NOT NULL COMMENT '话题ID',
`topicable_id` int(11) unsigned NOT NULL COMMENT '话题关系对应的ID',
`topicable_type` char(10) NOT NULL COMMENT '话题关系对应的类型 question、article',
`create_time` int(10) unsigned NOT NULL DEFAULT '0',
KEY `topic_id` (`topic_id`),
KEY `topicable_id` (`topicable_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
11. 通知表

CREATE TABLE `mc_notification` (
`notification_id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '通知ID',
`receiver_id` int(11) unsigned NOT NULL COMMENT '接收者ID',
`sender_id` int(11) NOT NULL COMMENT '发送者ID',
`type` varchar(40) NOT NULL COMMENT '消息类型:\r\nquestion_answered, \r\nquestion_commented, \r\nquestion_deleted, \r\narticle_commented, \r\narticle_deleted, \r\nanswer_commented, \r\nanswer_deleted, \r\ncomment_replied, \r\ncomment_deleted',
`article_id` int(11) NOT NULL COMMENT '文章ID',
`question_id` int(11) NOT NULL COMMENT '提问ID',
`answer_id` int(11) NOT NULL COMMENT '回答ID',
`comment_id` int(11) NOT NULL COMMENT '评论ID',
`reply_id` int(11) NOT NULL COMMENT '回复ID',
`content_deleted` text NOT NULL COMMENT '被删除的内容的备份',
`create_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '发送时间',
`read_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '阅读时间',
PRIMARY KEY (`notification_id`),
KEY `receiver_id` (`receiver_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='通知表';
12. 私信表
私信表 重要字段:
接收者ID、发送者ID、私信内容

CREATE TABLE `mc_inbox` (
`inbox_id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '私信ID',
`receiver_id` int(11) unsigned NOT NULL COMMENT '接收者ID',
`sender_id` int(11) unsigned NOT NULL COMMENT '发送者ID',
`content_markdown` text NOT NULL COMMENT '原始的私信内容',
`content_rendered` text NOT NULL COMMENT '过滤渲染后的私信内容',
`create_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '发送时间',
`read_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '阅读时间',
PRIMARY KEY (`inbox_id`),
KEY `receiver_id` (`receiver_id`),
KEY `sender_id` (`sender_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='私信表';
13. 关注关系表
关注关系表 重要字段:
用户ID、关注目标ID、关注目标类型

CREATE TABLE `mc_follow` (
`user_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '用户ID',
`followable_id` int(11) unsigned NOT NULL COMMENT '关注目标的ID',
`followable_type` char(10) NOT NULL COMMENT '关注目标类型 user、question、article、topic',
`create_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '关注时间',
KEY `followable_id` (`followable_id`),
KEY `user_id` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='文章关注关系表';
14. 图片表

CREATE TABLE `mc_image` (
`key` varchar(50) NOT NULL COMMENT '图片键名',
`filename` varchar(255) NOT NULL COMMENT '原始文件名',
`width` int(5) unsigned NOT NULL DEFAULT '0' COMMENT '原始图片宽度',
`height` int(5) unsigned NOT NULL DEFAULT '0' COMMENT '原始图片高度',
`create_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '上传时间',
`item_type` char(10) DEFAULT NULL COMMENT '关联类型:question、answer、article',
`item_id` int(11) NOT NULL DEFAULT '0' COMMENT '关联ID',
`user_id` int(11) NOT NULL COMMENT '用户ID',
PRIMARY KEY (`key`),
KEY `create_time` (`create_time`),
KEY `item_id` (`item_id`),
KEY `user_id` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
15. 设置表

CREATE TABLE `mc_option` (
`name` varchar(40) NOT NULL DEFAULT '' COMMENT '字段名',
`value` text NOT NULL COMMENT '字段值',
PRIMARY KEY (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='设置表';
16. 缓存表

CREATE TABLE `mc_cache` (
`name` varchar(180) NOT NULL,
`value` text NOT NULL,
`create_time` int(10) unsigned DEFAULT NULL COMMENT '创建时间',
`life_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '有效时间',
PRIMARY KEY (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='缓存表';
总结
一个简易版的论坛系统数据库设计到此结束。有问题评论区留言。
版权声明
本文为[BreezAm]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_43073558/article/details/120561526
边栏推荐
- Mysql database transaction example tutorial
- laravel编写Console脚本
- 解读机器人编程课程的生物认知度
- Upgrade the functions available for cpolar intranet penetration
- R-drop: a more powerful dropout regularization method
- Use of SVN:
- @Valid, @ validated learning notes
- Compress the curl library into a sending string of utf8 and send it with curl library
- map<QString, bool> 的使用记录
- Usage Summary of datetime and timestamp in MySQL
猜你喜欢

CUMCM 2021-b: preparation of C4 olefins by ethanol coupling (2)

Tensorflow使用keras创建神经网络的方法

分享两个实用的shell脚本

nacos基础(5):nacos配置入门

Usage of rename in cygwin

An interesting interview question

探究机器人教育的器材与教学

Structure of C language (Advanced)

Laravel绑定钉钉群警报(php)

Upgrade the functions available for cpolar intranet penetration
随机推荐
An interesting interview question
学习 Go 语言 0x03:理解变量之间的依赖以及初始化顺序
tensorflow常用的函数
nacos基础(5):nacos配置入门
Facing the global market, platefarm today logs in to four major global platforms such as Huobi
Promise details
R-drop: a more powerful dropout regularization method
MIT: label every pixel in the world with unsupervised! Humans: no more 800 hours for an hour of video
学习 Go 语言 0x06:《Go 语言之旅》中 斐波纳契闭包 练习题代码
Mysql排序的特性详情
QT信号量 无法解析的错误的总结
Detailed introduction to paging exploration of MySQL index optimization
Mysql系列SQL查询语句书写顺序及执行顺序详解
GPU, CUDA,cuDNN三者的關系總結
After the MySQL router is reinstalled, it reconnects to the cluster for boot - a problem that has been configured in this host before
How does QT turn qwigdet into qdialog
学习 Go 语言 0x01:从官网开始
Using Baidu PaddlePaddle EasyDL to accomplish specified target recognition
小程序 支付
Learn go language 0x03: understand the dependency between variables and initialization order