-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathdb-create-all.sql
322 lines (281 loc) · 13.8 KB
/
db-create-all.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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
create table blog (
id bigint auto_increment not null,
content TEXT,
when_edited datetime(6),
tweet_id bigint not null,
title varchar(255),
input_content TEXT,
author_id bigint not null,
content_type smallint,
version bigint not null,
when_created datetime(6) not null,
when_modified datetime(6) not null,
deleted tinyint(1) default 0 not null,
constraint pk_blog primary key (id)
);
create table blog_tag (
blog_id bigint not null,
tag_id bigint not null,
constraint pk_blog_tag primary key (blog_id,tag_id)
);
create table blog_stat (
id bigint auto_increment not null,
when_created datetime(6),
rank double,
float_up double,
tune integer,
likes integer,
views integer,
comments integer,
when_modified datetime(6) not null,
constraint pk_blog_stat primary key (id)
);
create table comment (
id bigint auto_increment not null,
content TEXT,
input_content TEXT,
author_id bigint not null,
source_type smallint,
source_id bigint,
reply_user_id bigint,
version bigint not null,
when_created datetime(6) not null,
when_modified datetime(6) not null,
constraint pk_comment primary key (id)
);
create table draft (
id bigint auto_increment not null,
target_id bigint,
title varchar(255),
content TEXT,
owner_id bigint,
version bigint not null,
when_created datetime(6) not null,
when_modified datetime(6) not null,
constraint pk_draft primary key (id)
);
create table fav (
id bigint auto_increment not null,
link varchar(255),
owner_id bigint,
version bigint not null,
when_created datetime(6) not null,
when_modified datetime(6) not null,
constraint pk_fav primary key (id)
);
create table feedback (
id bigint auto_increment not null,
content TEXT,
name varchar(255),
email varchar(255),
ip varchar(255),
version bigint not null,
when_created datetime(6) not null,
when_modified datetime(6) not null,
constraint pk_feedback primary key (id)
);
create table file_item (
id bigint auto_increment not null,
name varchar(255),
web_path varchar(255),
store_path varchar(255),
owner_id bigint,
version bigint not null,
when_created datetime(6) not null,
when_modified datetime(6) not null,
constraint pk_file_item primary key (id)
);
create table follow (
id bigint auto_increment not null,
source_id bigint not null,
target_id bigint not null,
reason varchar(255),
is_include_new tinyint(1) default 0,
is_include_all tinyint(1) default 0,
user_tag_offset bigint,
version bigint not null,
when_created datetime(6) not null,
when_modified datetime(6) not null,
constraint pk_follow primary key (id)
);
create table follow_tag (
follow_id bigint not null,
tag_id bigint not null,
constraint pk_follow_tag primary key (follow_id,tag_id)
);
create table liking (
id bigint auto_increment not null,
user_id bigint,
like_type smallint,
like_id bigint,
when_created datetime(6) not null,
constraint uq_liking_user_id_like_type_like_id unique (user_id,like_type,like_id),
constraint pk_liking primary key (id)
);
create table login_pass (
pass_id varchar(255) not null,
user_id bigint,
when_to_expire datetime(6),
version bigint not null,
when_created datetime(6) not null,
when_modified datetime(6) not null,
constraint pk_login_pass primary key (pass_id)
);
create table message (
id bigint auto_increment not null,
content varchar(255),
from_user bigint,
to_user bigint,
version bigint not null,
when_created datetime(6) not null,
when_modified datetime(6) not null,
constraint pk_message primary key (id)
);
create table notification (
id bigint auto_increment not null,
owner_id bigint,
sender_id bigint,
type integer,
source_id bigint,
is_read tinyint(1) default 0,
version bigint not null,
when_created datetime(6) not null,
when_modified datetime(6) not null,
constraint ck_notification_type check (type in (0,1,2,3,4,5,6,7,8,9)),
constraint pk_notification primary key (id)
);
create table tag (
id bigint auto_increment not null,
name varchar(255),
parent_id bigint,
is_core tinyint(1) default 0,
intro TEXT,
creator_id bigint,
version bigint not null,
when_created datetime(6) not null,
when_modified datetime(6) not null,
constraint pk_tag primary key (id)
);
create table tag_change_request (
id bigint auto_increment not null,
transactor_id bigint,
status integer,
parent_id bigint,
name varchar(255),
intro varchar(255),
tag_id bigint,
submitter_id bigint,
type integer,
version bigint not null,
when_created datetime(6) not null,
when_modified datetime(6) not null,
constraint ck_tag_change_request_status check (status in (0,1,2,3)),
constraint ck_tag_change_request_type check (type in (0,1,2)),
constraint pk_tag_change_request primary key (id)
);
create table tag_heed (
id bigint auto_increment not null,
user_id bigint not null,
tag_id bigint,
version bigint not null,
when_created datetime(6) not null,
when_modified datetime(6) not null,
constraint pk_tag_heed primary key (id)
);
create table tweet (
id bigint auto_increment not null,
input_content TEXT,
content TEXT,
rich_elements_json TEXT,
mid_forwards_json TEXT,
author_id bigint not null,
origin_id bigint not null,
blog_id bigint not null,
deleted tinyint(1) default 0,
version bigint not null,
when_created datetime(6) not null,
when_modified datetime(6) not null,
constraint pk_tweet primary key (id)
);
create table tweet_tag (
tweet_id bigint not null,
tag_id bigint not null,
constraint pk_tweet_tag primary key (tweet_id,tag_id)
);
create table tweet_stat (
id bigint auto_increment not null,
when_created datetime(6),
rank double,
float_up double,
tune integer,
likes integer,
views integer,
forwards integer,
comments integer,
when_modified datetime(6) not null,
constraint pk_tweet_stat primary key (id)
);
create table user (
id bigint auto_increment not null,
email varchar(255),
password varchar(255),
name varchar(255),
avatar varchar(255),
intro varchar(255),
authority integer,
version bigint not null,
when_created datetime(6) not null,
when_modified datetime(6) not null,
constraint ck_user_authority check (authority in (0,1,2)),
constraint pk_user primary key (id)
);
create table user_tag (
id bigint auto_increment not null,
user_id bigint,
tag_id bigint,
version bigint not null,
when_created datetime(6) not null,
when_modified datetime(6) not null,
constraint uq_user_tag_user_id_tag_id unique (user_id,tag_id),
constraint pk_user_tag primary key (id)
);
create index ix_blog_stat_rank on blog_stat (rank);
create index ix_tweet_stat_rank on tweet_stat (rank);
alter table blog add constraint fk_blog_author_id foreign key (author_id) references user (id) on delete restrict on update restrict;
create index ix_blog_author_id on blog (author_id);
alter table blog_tag add constraint fk_blog_tag_blog foreign key (blog_id) references blog (id) on delete restrict on update restrict;
create index ix_blog_tag_blog on blog_tag (blog_id);
alter table blog_tag add constraint fk_blog_tag_tag foreign key (tag_id) references tag (id) on delete restrict on update restrict;
create index ix_blog_tag_tag on blog_tag (tag_id);
alter table comment add constraint fk_comment_author_id foreign key (author_id) references user (id) on delete restrict on update restrict;
create index ix_comment_author_id on comment (author_id);
alter table draft add constraint fk_draft_owner_id foreign key (owner_id) references user (id) on delete restrict on update restrict;
create index ix_draft_owner_id on draft (owner_id);
alter table fav add constraint fk_fav_owner_id foreign key (owner_id) references user (id) on delete restrict on update restrict;
create index ix_fav_owner_id on fav (owner_id);
alter table follow add constraint fk_follow_source_id foreign key (source_id) references user (id) on delete restrict on update restrict;
create index ix_follow_source_id on follow (source_id);
alter table follow add constraint fk_follow_target_id foreign key (target_id) references user (id) on delete restrict on update restrict;
create index ix_follow_target_id on follow (target_id);
alter table follow_tag add constraint fk_follow_tag_follow foreign key (follow_id) references follow (id) on delete restrict on update restrict;
create index ix_follow_tag_follow on follow_tag (follow_id);
alter table follow_tag add constraint fk_follow_tag_tag foreign key (tag_id) references tag (id) on delete restrict on update restrict;
create index ix_follow_tag_tag on follow_tag (tag_id);
alter table tag add constraint fk_tag_parent_id foreign key (parent_id) references tag (id) on delete restrict on update restrict;
create index ix_tag_parent_id on tag (parent_id);
alter table tag_change_request add constraint fk_tag_change_request_transactor_id foreign key (transactor_id) references user (id) on delete restrict on update restrict;
create index ix_tag_change_request_transactor_id on tag_change_request (transactor_id);
alter table tag_change_request add constraint fk_tag_change_request_tag_id foreign key (tag_id) references tag (id) on delete restrict on update restrict;
create index ix_tag_change_request_tag_id on tag_change_request (tag_id);
alter table tag_change_request add constraint fk_tag_change_request_submitter_id foreign key (submitter_id) references user (id) on delete restrict on update restrict;
create index ix_tag_change_request_submitter_id on tag_change_request (submitter_id);
alter table tag_heed add constraint fk_tag_heed_user_id foreign key (user_id) references user (id) on delete restrict on update restrict;
create index ix_tag_heed_user_id on tag_heed (user_id);
alter table tag_heed add constraint fk_tag_heed_tag_id foreign key (tag_id) references tag (id) on delete restrict on update restrict;
create index ix_tag_heed_tag_id on tag_heed (tag_id);
alter table tweet add constraint fk_tweet_author_id foreign key (author_id) references user (id) on delete restrict on update restrict;
create index ix_tweet_author_id on tweet (author_id);
alter table tweet_tag add constraint fk_tweet_tag_tweet foreign key (tweet_id) references tweet (id) on delete restrict on update restrict;
create index ix_tweet_tag_tweet on tweet_tag (tweet_id);
alter table tweet_tag add constraint fk_tweet_tag_tag foreign key (tag_id) references tag (id) on delete restrict on update restrict;
create index ix_tweet_tag_tag on tweet_tag (tag_id);