-
Notifications
You must be signed in to change notification settings - Fork 2
/
yunyin.sql
358 lines (301 loc) · 12.7 KB
/
yunyin.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
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
/*==============================================================*/
/* DBMS name: MySQL 5.0 */
/* Created on: 2015/6/6 19:00:00 */
/*==============================================================*/
-- drop table if exists card;
-- drop table if exists cardlog;
drop table if exists code;
drop table if exists device;
drop table if exists feedback;
drop table if exists file;
drop table if exists notification;
drop table if exists printer;
drop table if exists school;
drop table if exists token;
drop table if exists user;
drop table if exists share;
drop table if exists hastag;
drop table if exists tag;
SET names utf8;
/*==============================================================*/
/* Table: card */
/*==============================================================*/
-- create table card
-- (
-- id bigint not null,
-- off tinyint default 0,
-- blocked bool default 0,
-- primary key (id)
-- );
/*==============================================================*/
/* Table: cardlog */
/*==============================================================*/
-- create table cardlog
-- (
-- id bigint not null auto_increment,
-- find_id bigint not null,
-- lost_id bigint not null,
-- time timestamp default CURRENT_TIMESTAMP,
-- status tinyint,
-- primary key (id)
-- );
/*==============================================================*/
/* Table: code */
/*==============================================================*/
create table code
(
id bigint not null auto_increment,
use_id bigint not null,
code char(32),
time timestamp not null default CURRENT_TIMESTAMP,
type tinyint,
content varchar(64),
primary key (id)
);
/*==============================================================*/
/* Table: device */
/*==============================================================*/
/*
create table device
(
id bigint not null,
code varchar(16),
last_login timestamp default CURRENT_TIMESTAMP,
status tinyint,
type tinyint,
primary key (id)
);*/
/*==============================================================*/
/* Table: feedback */
/*==============================================================*/
create table feedback
(
id bigint not null auto_increment,
email char(32),
phone char(16),
message text,
time timestamp not null default CURRENT_TIMESTAMP,
primary key (id)
);
/*==============================================================*/
/* Table: file */
/*==============================================================*/
create table file
(
id bigint not null auto_increment,
use_id bigint not null,
name varchar(32),
url char(48),
time timestamp not null default CURRENT_TIMESTAMP,
status tinyint not null default 1,
primary key (id)
);
create table task
(
id bigint not null auto_increment,
use_id bigint not null,
pri_id bigint not null,
url char(48) not null,
name varchar(32),
requirements varchar(128),
copies int default 1,
`double` bool,
status tinyint default 1,
color bool,
format tinyint default 0,
payed tinyint default 0,
time timestamp not null default CURRENT_TIMESTAMP,
primary key (id)
);
/*==============================================================*/
/* Table: notification */
/*==============================================================*/
-- create table notification
-- (
-- id bigint not null auto_increment,
-- tas_id bigint not null,
-- content text,
-- to_id bigint,
-- type tinyint,
-- primary key (id)
-- );
/*==============================================================*/
/* Table: printer */
/*==============================================================*/
create table printer
(
id bigint not null auto_increment,
sch_id bigint not null,
name char(16) not null,
account char(16) not null,
password char(32) not null,
address char(32),
email varchar(64),
phone char(16),
qq char(16),
wechat char(16),
profile text,
image varchar(64),
open varchar(32),
status tinyint default 1,
rank int default 0,
price text,
other text,
primary key (id),
unique key AK_account_unique (account)
);
/*==============================================================*/
/* Table: school */
/*==============================================================*/
create table school
(
id bigint not null auto_increment,
name char(32),
address varchar(128),
abbr char(8),
verify varchar(16),
verifyurl varchar(32),
primary key (id)
);
/*==============================================================*/
/* Table: token */
/*==============================================================*/
create table token
(
to_id bigint not null,
type tinyint not null,
time timestamp not null default CURRENT_TIMESTAMP,
token char(48),
primary key (to_id, type),
unique key AK_token_unique (token)
);
/*==============================================================*/
/* Table: user */
/*==============================================================*/
create table user
(
id bigint not null auto_increment,
sch_id bigint not null,
number char(12),
password char(32),
name char(8),
gender char(2),
phone char(16),
email char(64),
status tinyint default 1,
regtime timestamp default CURRENT_TIMESTAMP,
primary key (id),
unique key AK_number_unique (number,sch_id)
);
/*==============================================================*/
/* Table: share */
/*==============================================================*/
create table share
(
id bigint not null auto_increment,
fil_id bigint not null,
use_id bigint not null,
detail text,
url char(48),
time timestamp not null default CURRENT_TIMESTAMP,
name char(32) not null,
anonymous bool,
reference bigint default 0,
primary key(id),
unique key share_file_unique (fil_id),
unique key share_url_unique (url),
check(reference >= 0)
);
/*==============================================================*/
/* Table: tag */
/*==============================================================*/
create table tag
(
id bigint not null auto_increment,
use_id bigint not null,
name char(16) not null,
count bigint default 0,
time timestamp not null default CURRENT_TIMESTAMP,
primary key(id),
unique key tag_name_unique (name)
);
/*==============================================================*/
/* Table: hastag */
/*==============================================================*/
create table hastag
(
sha_id bigint not null,
tag_id bigint not null,
time timestamp not null default CURRENT_TIMESTAMP,
primary key(sha_id,tag_id)
);
-- create table usershare
-- (
-- sha_id bigint not null,
-- use_id bigint not null,
-- time timestamp not null default CURRENT_TIMESTAMP,
-- primary key(sha_id,use_id)
-- );
/*=================================================教材*/
create table book
(
id bigint not null auto_increment,
pri_id bigint not null,
name char(32) not null,
price varchar(32) not null,
image varchar(64),
detail text,
count int default 0,
time timestamp not null default CURRENT_TIMESTAMP,
primary key(id)
);
-- alter table card add constraint FK_card_info_of_user foreign key (id)
-- references user (id) on delete restrict on update restrict;
-- alter table cardlog add constraint FK_user_find_card foreign key (find_id)
-- references user (id) on delete restrict on update restrict;
-- alter table cardlog add constraint FK_user_lost_card foreign key (lost_id)
-- references user (id) on delete restrict on update restrict;
alter table code add constraint FK_code_of_user foreign key (use_id)
references user (id) on delete restrict on update restrict;
/*alter table device add constraint FK_mobile_device_of_user foreign key (id)
references user (id) on delete restrict on update restrict;*/
alter table task add constraint FK_task_of_printer foreign key (pri_id)
references printer (id) on delete restrict on update restrict;
alter table task add constraint FK_task_of_user foreign key (use_id)
references user (id) on delete restrict on update restrict;
-- alter table task add constraint FK_task_of_file foreign key (fil_id)
-- references file (id) on delete restrict on update restrict;
-- alter table notification add constraint FK_notification_of_task foreign key (task_id)
-- references task (id) on delete restrict on update restrict;
alter table printer add constraint FK_printer_blong_to_school foreign key (sch_id)
references school (id) on delete restrict on update restrict;
alter table user add constraint FK_user_blong_to_school foreign key (sch_id)
references school (id) on delete restrict on update restrict;
alter table share add constraint FK_share_of_file foreign key (fil_id)
references file (id) on delete restrict on update restrict;
alter table tag add constraint FK_tag_of_user foreign key (use_id)
references user (id) on delete restrict on update restrict;
alter table hastag add constraint FK_connection_of_share foreign key (sha_id)
references share (id) on delete restrict on update restrict;
alter table hastag add constraint FK_connetction_of_tag foreign key (tag_id)
references tag (id) on delete restrict on update restrict;
-- alter table usershare add constraint FK_usershare_of_share foreign key (sha_id)
-- references share (id) on delete restrict on update restrict;
-- alter table usershare add constraint FK_usershare_of_user foreign key (use_id)
-- references user (id) on delete restrict on update restrict;
alter table share add constraint FK_share_of_user foreign key (use_id)
references user (id) on delete restrict on update restrict;
alter table book add constraint FK_book_of_printer foreign key (pri_id)
references printer (id) on delete restrict on update restrict;
alter table file add constraint FK_file_of_task foreign key (use_id)
references user (id) on delete restrict on update restrict;
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
INSERT INTO `school` (`id`, `name`, `address`,`abbr`,`verify`,`verifyurl`) VALUES
(1, '南开大学', '天津市 南开区 卫津路94号','nku','信息门户(URP)','http://urp.nku.cn'),
(2, '天津大学', '天津市 南开区 卫津路92号','tju','天大办公网','http://e.tju.edu.cn'),
(3, '天津商职', '天津市 海河教育园 雅观路23号','tifert','教务处网站','http://jw.tifert.edu.cn/2003/'),
(4, '河北工业大学', '天津市 北辰区 西平道5340号', 'hebut', '综合教务系统', 'http://115.24.160.162/'),
(5, '广州番禺职业学院', '广东省 广州市 番禺区市良路1342号','gzpyp','教务处网站','http://jw.gzpyp.edu.cn/'),
(6, '湖南理工学院', '湖南省 岳阳市 岳阳楼区学院路439号', 'hnist', '信息服务系统', 'http://info.hnist.cn/'),
(0, '无学校', '','all','','');
INSERT INTO `user`(`id`,`sch_id`) VALUES ('0','0' );