forked from xiaolongzuo/personal-blog-webapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.sql
279 lines (228 loc) · 9.15 KB
/
db.sql
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
ALTER SCHEMA `blog` DEFAULT CHARACTER SET utf8mb4 ;
DROP TABLE IF EXISTS comments;
DROP TABLE IF EXISTS article_id_visitor_ip;
DROP TABLE IF EXISTS articles;
DROP TABLE IF EXISTS access_log;
CREATE TABLE articles
(
id INT NOT NULL AUTO_INCREMENT,
username CHAR(15) NOT NULL,
resource_id VARCHAR(100) NOT NULL,
subject VARCHAR (100) NOT NULL,
html LONGTEXT NOT NULL,
content LONGTEXT NOT NULL,
icon VARCHAR (200) NOT NULL,
create_date TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00',
modify_date TIMESTAMP NULL DEFAULT '0000-00-00 00:00:00',
access_times INT DEFAULT 0,
comment_times INT DEFAULT 0,
good_times INT DEFAULT 0,
touch_times INT DEFAULT 0,
funny_times INT DEFAULT 0,
happy_times INT DEFAULT 0,
anger_times INT DEFAULT 0,
bored_times INT DEFAULT 0,
water_times INT DEFAULT 0,
surprise_times INT DEFAULT 0,
PRIMARY KEY(id)
) ENGINE=INNODB DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT = 1;
alter table articles add unique(resource_id);
CREATE TABLE comments
(
id INT NOT NULL AUTO_INCREMENT,
content TEXT NOT NULL,
visitor_ip char(20) NOT NULL,
city char(20) NOT NULL,
article_id INT NOT NULL ,
create_date TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00',
modify_date TIMESTAMP NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY(id)
) ENGINE=INNODB DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT = 1;
ALTER TABLE comments ADD CONSTRAINT `COMMENTS_FK_ARTICLE_ID` FOREIGN KEY (`article_id`) REFERENCES articles(`id`);
create table article_id_visitor_ip (
article_id INT NOT NULL,
visitor_ip char(20) NOT NULL,
primary key (article_id,visitor_ip)
) ENGINE=INNODB DEFAULT CHARSET=utf8mb4 ;
ALTER TABLE article_id_visitor_ip ADD CONSTRAINT `ARTICLE_ID_VISITOR_IP_FK_ARTICLE_ID` FOREIGN KEY (`article_id`) REFERENCES articles(`id`);
create table access_log (
id INT NOT NULL AUTO_INCREMENT,
visitor_ip char(20) NOT NULL,
url VARCHAR (200) NOT NULL,
access_date TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00',
city CHAR (20) NOT NULL,
params LONGTEXT ,
primary key (id)
) ENGINE=INNODB DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT = 1;
DROP TABLE IF EXISTS matches;
DROP TABLE IF EXISTS hero;
create table matches (
id INT NOT NULL AUTO_INCREMENT,
attack VARCHAR(50) NOT NULL,
defend VARCHAR(50) NOT NULL,
result TINYINT NOT NULL,
primary key (id)
) ENGINE=INNODB DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT = 1;
create table hero (
full_name VARCHAR(20) NOT NULL,
aliases VARCHAR(200),
primary key (full_name)
) ENGINE=INNODB DEFAULT CHARSET=utf8mb4;
alter table matches add count int(11) default 1;
alter table matches add record_date timestamp default '0000-00-00 00:00:00';
alter table articles add status tinyint default 1;
create table html_page (
id INT NOT NULL AUTO_INCREMENT,
url VARCHAR(500),
is_push tinyint,
push_date timestamp default '0000-00-00 00:00:00',
create_date timestamp default '0000-00-00 00:00:00',
primary key (id)
) ENGINE=INNODB DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT = 1;
create table users (
id INT NOT NULL AUTO_INCREMENT,
username VARCHAR (40) NOT NULL,
password VARCHAR (40) ,
nick_name VARCHAR (40) ,
qq_open_id VARCHAR (40) ,
qq_nick_name VARCHAR (40),
qq_avatar_url_30 VARCHAR(200),
primary key (id)
) ENGINE=INNODB DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT = 1;
alter table users add unique(username);
alter table comments add username VARCHAR (40);
alter table comments add nick_name VARCHAR (40);
create table tags (
id INT NOT NULL AUTO_INCREMENT,
tag_name VARCHAR(20),
primary key (id)
) ENGINE=INNODB DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT = 1;
create table article_tag (
article_id INT NOT NULL,
tag_id INT NOT NULL,
primary key (article_id,tag_id)
) ENGINE=INNODB DEFAULT CHARSET=utf8mb4;
ALTER TABLE article_tag ADD CONSTRAINT `ARTICLE_TAG_FK_ARTICLE_ID` FOREIGN KEY (`article_id`) REFERENCES articles(`id`);
ALTER TABLE article_tag ADD CONSTRAINT `ARTICLE_TAG_FK_TAG_ID` FOREIGN KEY (`tag_id`) REFERENCES tags(`id`);
create table categories (
id INT NOT NULL AUTO_INCREMENT,
category_name VARCHAR(20),
primary key (id)
) ENGINE=INNODB DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT = 1;
create table article_category (
article_id INT NOT NULL,
category_id INT NOT NULL,
primary key (article_id,category_id)
) ENGINE=INNODB DEFAULT CHARSET=utf8mb4;
ALTER TABLE article_category ADD CONSTRAINT `ARTICLE_CATEGORY_FK_ARTICLE_ID` FOREIGN KEY (`article_id`) REFERENCES articles(`id`);
ALTER TABLE article_category ADD CONSTRAINT `ARTICLE_CATEGORY_FK_CATEGORY_ID` FOREIGN KEY (`category_id`) REFERENCES categories(`id`);
ALTER TABLE comments add reference_comment_id INT ;
ALTER TABLE comments add resource_id VARCHAR(40) ;
ALTER TABLE comments add good_times INT DEFAULT 0;
ALTER TABLE comments add bad_times INT DEFAULT 0;
ALTER TABLE comments ADD CONSTRAINT `COMMENTS_FK_REFERENCE_COMMENT_ID` FOREIGN KEY (`reference_comment_id`) REFERENCES comments(`id`);
create table comment_id_visitor_ip (
comment_id INT NOT NULL,
visitor_ip char(20) NOT NULL,
primary key (comment_id,visitor_ip)
) ENGINE=INNODB DEFAULT CHARSET=utf8mb4 ;
ALTER TABLE comment_id_visitor_ip ADD CONSTRAINT `COMMENT_ID_VISITOR_IP_FK_ARTICLE_ID` FOREIGN KEY (`comment_id`) REFERENCES comments(`id`);
ALTER TABLE comment_id_visitor_ip add username VARCHAR(40) ;
ALTER TABLE article_id_visitor_ip add username VARCHAR(40) ;
create table images (
id INT NOT NULL AUTO_INCREMENT,
path VARCHAR(200) NOT NULL,
resource_url VARCHAR(200),
primary key (id)
) ENGINE=INNODB DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT = 1;
ALTER TABLE users add create_date TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00';
create table dictionaries (
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(200) NOT NULL,
type VARCHAR(10),
primary key (id)
) ENGINE=INNODB DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT = 1;
CREATE TABLE dictionary_province (
id int(10) unsigned NOT NULL default 0,
name varchar(30) NOT NULL,
type varchar(1) default NULL COMMENT '1 - 直辖市\r\n2 - 行政省\r\n3 - 自治区\r\n4 - 特别行政区\r\n5 - 其他国家\r\n见全局数据字典[省份类型] \r\n',
state varchar(1) default NULL COMMENT '0 - 禁用\r\n1 - 启用',
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE dictionary_city (
id int(10) unsigned NOT NULL default '0',
name varchar(30) NOT NULL,
province_id int(10) unsigned NOT NULL,
state varchar(1) default '1' COMMENT '0 - 禁用\r\n1 - 启用 \r\n',
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
alter table users add province VARCHAR (200);
alter table users add city VARCHAR (200);
alter table users add language_id int(11);
alter table users add CONSTRAINT `USERS_FK_LANGUAGE_ID` FOREIGN KEY (`language_id`) REFERENCES dictionaries(`id`);
alter table users drop qq_nick_name ;
alter table users change qq_avatar_url_30 image_path VARCHAR(200);
ALTER TABLE articles CHANGE COLUMN resource_id resource_id VARCHAR(100) NULL ;
alter table comments change nick_name resource_username VARCHAR (40);
create table questions (
id INT NOT NULL AUTO_INCREMENT,
title VARCHAR(200) NOT NULL,
description TEXT NOT NULL,
username VARCHAR (40),
create_date TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00',
primary key (id)
) ENGINE=INNODB DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT = 1;
create table answers (
id INT NOT NULL AUTO_INCREMENT,
question_id INT NOT NULL,
answer TEXT NOT NULL,
visitor_ip char(20) NOT NULL,
city char(20) NOT NULL,
username VARCHAR (40),
answer_date TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00',
reference_answer_id INT,
primary key (id)
) ENGINE=INNODB DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT = 1;
alter table answers add CONSTRAINT `ANSWERS_FK_QUESTION_ID` FOREIGN KEY (`question_id`) REFERENCES questions(`id`);
alter table questions add content TEXT NOT NULL;
alter table questions add access_times INT DEFAULT 0;
alter table questions add answer_number INT DEFAULT 0;
alter table questions add is_resolved TINYINT DEFAULT 0;
alter table questions add solution_id INT DEFAULT 0;
alter table answers add good_times INT DEFAULT 0;
alter table answers add bad_times INT DEFAULT 0;
create table answer_id_visitor_ip (
answer_id INT NOT NULL,
visitor_ip char(20) NOT NULL,
primary key (answer_id,visitor_ip)
) ENGINE=INNODB DEFAULT CHARSET=utf8mb4 ;
ALTER TABLE answer_id_visitor_ip add username VARCHAR(40) ;
create table records (
id INT NOT NULL AUTO_INCREMENT,
title VARCHAR(100),
record TEXT NOT NULL,
content VARCHAR(1500),
username VARCHAR (40),
create_date TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00',
access_times INT DEFAULT 0,
good_times INT DEFAULT 0,
primary key (id)
) ENGINE=INNODB DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT = 1;
create table record_id_visitor_ip (
record_id INT NOT NULL,
visitor_ip char(20) NOT NULL,
username VARCHAR(40),
primary key (record_id,visitor_ip)
) ENGINE=INNODB DEFAULT CHARSET=utf8mb4 ;
create table messages (
id INT NOT NULL AUTO_INCREMENT,
message VARCHAR(1000) NOT NULL,
visitor_ip char(20) NOT NULL,
city char(20) NOT NULL,
username VARCHAR (40),
create_date TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00',
reference_message_id INT,
primary key (id)
) ENGINE=INNODB DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT = 1;
alter table articles add type TINYINT(1) NOT NULL DEFAULT 0;
/* 生产到此 */