Repository navigation
Expand file tree
/
Copy pathdatabase.sql
More file actions
195 lines (176 loc) · 9.93 KB
/
Copy pathdatabase.sql
File metadata and controls
195 lines (176 loc) · 9.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/*
Navicat Premium Data Transfer
Source Server : company
Source Server Type : MySQL
Source Server Version : 50724
Source Host : localhost:3306
Source Schema : study
Target Server Type : MySQL
Target Server Version : 50724
File Encoding : 65001
Date: 25/06/2024 19:54:37
*/
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for db_account
-- ----------------------------
DROP TABLE IF EXISTS `db_account`;
CREATE TABLE `db_account` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`email` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`password` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`role` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`avatar` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`register_time` datetime NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE,
UNIQUE INDEX `unique_email`(`email`) USING BTREE,
UNIQUE INDEX `unique_username`(`username`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 9 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Table structure for db_account_details
-- ----------------------------
DROP TABLE IF EXISTS `db_account_details`;
CREATE TABLE `db_account_details` (
`id` int(11) NOT NULL,
`gender` tinyint(4) NULL DEFAULT NULL,
`phone` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`qq` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`wx` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`introduction` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Table structure for db_account_privacy
-- ----------------------------
DROP TABLE IF EXISTS `db_account_privacy`;
CREATE TABLE `db_account_privacy` (
`id` int(11) NOT NULL,
`phone` tinyint(4) NULL DEFAULT NULL,
`email` tinyint(4) NULL DEFAULT NULL,
`qq` tinyint(4) NULL DEFAULT NULL,
`wx` tinyint(4) NULL DEFAULT NULL,
`gender` tinyint(4) NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Table structure for db_chat
-- ----------------------------
DROP TABLE IF EXISTS `db_chat`;
CREATE TABLE `db_chat` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(11) NOT NULL,
`session_id` int(11) NOT NULL,
`question` text CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`answer` text CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`) USING BTREE,
INDEX `user_id`(`user_id`) USING BTREE,
INDEX `db_session_id`(`session_id`) USING BTREE,
CONSTRAINT `db_chat_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `db_account` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
CONSTRAINT `db_session_id` FOREIGN KEY (`session_id`) REFERENCES `db_chat_session` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE = InnoDB AUTO_INCREMENT = 65 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Table structure for db_chat_session
-- ----------------------------
DROP TABLE IF EXISTS `db_chat_session`;
CREATE TABLE `db_chat_session` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(11) NULL DEFAULT NULL,
`session_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`created_at` date NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 7 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Table structure for db_image_store
-- ----------------------------
DROP TABLE IF EXISTS `db_image_store`;
CREATE TABLE `db_image_store` (
`uid` int(11) NOT NULL,
`name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`time` datetime NULL DEFAULT NULL
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Table structure for db_notification
-- ----------------------------
DROP TABLE IF EXISTS `db_notification`;
CREATE TABLE `db_notification` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`uid` int(11) NULL DEFAULT NULL,
`title` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`content` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`type` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`url` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`time` datetime NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 15 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Table structure for db_topic
-- ----------------------------
DROP TABLE IF EXISTS `db_topic`;
CREATE TABLE `db_topic` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`content` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL,
`uid` int(11) NULL DEFAULT NULL,
`type` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`time` datetime NULL DEFAULT NULL,
`top` tinyint(4) NULL DEFAULT 0,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 33 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Table structure for db_topic_comment
-- ----------------------------
DROP TABLE IF EXISTS `db_topic_comment`;
CREATE TABLE `db_topic_comment` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`uid` int(11) NULL DEFAULT NULL,
`tid` int(11) NULL DEFAULT NULL,
`content` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL,
`time` datetime NULL DEFAULT NULL,
`quote` int(11) NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 68 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Table structure for db_topic_interact_collect
-- ----------------------------
DROP TABLE IF EXISTS `db_topic_interact_collect`;
CREATE TABLE `db_topic_interact_collect` (
`tid` int(11) NULL DEFAULT NULL,
`uid` int(11) NULL DEFAULT NULL,
`time` datetime NULL DEFAULT NULL,
UNIQUE INDEX `tid_uid_collect`(`tid`, `uid`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Table structure for db_topic_interact_like
-- ----------------------------
DROP TABLE IF EXISTS `db_topic_interact_like`;
CREATE TABLE `db_topic_interact_like` (
`tid` int(11) NULL DEFAULT NULL,
`uid` int(11) NULL DEFAULT NULL,
`time` datetime NULL DEFAULT NULL,
UNIQUE INDEX `tid_uid_like`(`tid`, `uid`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Table structure for db_topic_type
-- ----------------------------
DROP TABLE IF EXISTS `db_topic_type`;
CREATE TABLE `db_topic_type` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`description` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`color` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 7 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- View structure for user_post_statistics
-- ----------------------------
DROP VIEW IF EXISTS `user_post_statistics`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `user_post_statistics` AS select `db_account`.`id` AS `user_id`,`db_account`.`username` AS `user_name`,count(`db_topic_interact_like`.`tid`) AS `total_likes`,count(`db_topic_interact_collect`.`tid`) AS `total_collects`,(select count(0) from `db_topic_comment` where (`db_topic_comment`.`uid` = `db_account`.`id`)) AS `total_comments` from ((`db_account` left join `db_topic_interact_like` on((`db_topic_interact_like`.`uid` = `db_account`.`id`))) left join `db_topic_interact_collect` on((`db_topic_interact_collect`.`uid` = `db_account`.`id`))) group by `db_account`.`id`,`db_account`.`username`;
-- ----------------------------
-- View structure for view_topic_hotness
-- ----------------------------
DROP VIEW IF EXISTS `view_topic_hotness`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `view_topic_hotness` AS select `t`.`id` AS `topic_id`,`t`.`title` AS `title`,`t`.`content` AS `content`,`t`.`uid` AS `uid`,`t`.`type` AS `type`,`t`.`time` AS `time`,coalesce(`likes`.`like_count`,0) AS `like_count`,coalesce(`collects`.`collect_count`,0) AS `collect_count`,coalesce(`comments`.`comment_count`,0) AS `comment_count`,(((coalesce(`likes`.`like_count`,0) * 2) + (coalesce(`collects`.`collect_count`,0) * 1.5)) + (coalesce(`comments`.`comment_count`,0) * 3)) AS `hotness` from (((`study`.`db_topic` `t` left join (select `study`.`db_topic_interact_like`.`tid` AS `tid`,count(0) AS `like_count` from `study`.`db_topic_interact_like` group by `study`.`db_topic_interact_like`.`tid`) `likes` on((`t`.`id` = `likes`.`tid`))) left join (select `study`.`db_topic_interact_collect`.`tid` AS `tid`,count(0) AS `collect_count` from `study`.`db_topic_interact_collect` group by `study`.`db_topic_interact_collect`.`tid`) `collects` on((`t`.`id` = `collects`.`tid`))) left join (select `study`.`db_topic_comment`.`tid` AS `tid`,count(0) AS `comment_count` from `study`.`db_topic_comment` group by `study`.`db_topic_comment`.`tid`) `comments` on((`t`.`id` = `comments`.`tid`)));
SET FOREIGN_KEY_CHECKS = 1;