-
Notifications
You must be signed in to change notification settings - Fork 0
/
sql_create
62 lines (56 loc) · 2.16 KB
/
sql_create
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
CREATE TABLE `user` (
`id` int NOT NULL AUTO_INCREMENT COMMENT 'Primary Key',
`username` varchar(16) NOT NULL COMMENT 'Username',
`token` varchar(255) NOT NULL COMMENT 'User token, user unique',
`register_time` datetime NOT NULL COMMENT 'Register Time',
`last_updated_time` datetime NOT NULL COMMENT 'This row last updated time',
`last_login_time` datetime NOT NULL COMMENT 'Last login time',
`type` varchar(16) NOT NULL COMMENT 'master, manager, menber, user, visiter',
PRIMARY KEY (`id`),
UNIQUE KEY `username` (`username`),
UNIQUE KEY `token` (`token`)
) COMMENT '';
CREATE TABLE `user_config` (
`id` int NOT NULL AUTO_INCREMENT COMMENT 'Primary Key',
`user_id` int NOT NULL COMMENT 'User foreign key',
`theme` varchar(16) DEFAULT NULL COMMENT 'Color theme',
`web_worker_num` int DEFAULT 4,
`filelist_config` TEXT DEFAULT NULL COMMENT 'map path to its config',
PRIMARY KEY (`id`),
KEY `user_id` (`user_id`),
CONSTRAINT `user_config_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`)
) COMMENT '';
CREATE TABLE `user_file_action` (
`id` int NOT NULL AUTO_INCREMENT COMMENT 'Primary Key',
`user_id` int NOT NULL COMMENT 'User foreign key',
`filename` varchar(16) DEFAULT NULL COMMENT '',
`filepath` varchar(255) DEFAULT NULL COMMENT '',
`action` varchar(32) DEFAULT NULL COMMENT 'upload, download, delete, share',
`create_time` datetime NOT NULL COMMENT 'action create time',
PRIMARY KEY (`id`),
KEY `user_id` (`user_id`),
FOREIGN KEY (`user_id`) REFERENCES `user` (`id`)
) COMMENT '';
DELIMITER $$
CREATE TRIGGER `before_user_insert` BEFORE INSERT ON `user`
FOR EACH ROW
BEGIN
SET NEW.register_time = NOW();
SET NEW.last_updated_time = NOW();
SET NEW.last_login_time = NOW();
END$$
CREATE TRIGGER `before_user_update` BEFORE UPDATE ON `user`
FOR EACH ROW
BEGIN
IF OLD.last_login_time != NEW.last_login_time THEN
SET NEW.last_updated_time = NOW();
ELSE
SET NEW.last_updated_time = NOW();
END IF;
END$$
CREATE TRIGGER `before_file_action_insert` BEFORE INSERT ON `user_file_action`
FOR EACH ROW
BEGIN
SET NEW.create_time = NOW();
END$$
DELIMITER ;