forked from mitodl/response-map
-
Notifications
You must be signed in to change notification settings - Fork 0
/
response_map.sql
70 lines (64 loc) · 2.58 KB
/
response_map.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
--
-- Table structure for table `resource`
--
SET foreign_key_checks = 0;
DROP TABLE IF EXISTS `user`;
CREATE TABLE IF NOT EXISTS `user` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`userId` VARCHAR(36) NOT NULL,
`username` VARCHAR(36) DEFAULT NULL,
`firstname` VARCHAR(80) DEFAULT NULL,
`lastname` VARCHAR(80) DEFAULT NULL,
-- The maximum length for an email address is 254 chars by RFC3696 errata
`email` VARCHAR(254) DEFAULT NULL,
`create_time` TIMESTAMP NOT NULL DEFAULT 0,
`update_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
UNIQUE (`userId`),
UNIQUE (`username`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
DROP TABLE IF EXISTS `resource`;
CREATE TABLE IF NOT EXISTS `resource` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`course_id` VARCHAR(255) NOT NULL,
`map_id` VARCHAR(255) NOT NULL,
`name` VARCHAR(255) DEFAULT NULL,
`create_time` TIMESTAMP NOT NULL DEFAULT 0,
`update_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
UNIQUE no_duplicates (`course_id`, `map_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
DROP TABLE IF EXISTS `response`;
CREATE TABLE IF NOT EXISTS `response` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`user_id` INT(11) NOT NULL,
`resource_id` INT(11) NOT NULL,
`head` VARCHAR(255) DEFAULT NULL,
`description` TEXT,
`location` VARCHAR(255) NOT NULL,
`latitude` DECIMAL(10,8) NOT NULL,
`longitude` DECIMAL(11,8) NOT NULL,
`image_url` VARCHAR(255) DEFAULT NULL,
`thumbnail_url` VARCHAR(255) DEFAULT NULL,
`url` VARCHAR(2000) DEFAULT NULL,
`deleted` TINYINT(1) NOT NULL DEFAULT 0,
`create_time` TIMESTAMP NOT NULL DEFAULT 0,
`update_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
FOREIGN KEY (`resource_id`) REFERENCES `resource` (`id`) ON DELETE CASCADE,
FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
DROP TABLE IF EXISTS `feedback`;
CREATE TABLE IF NOT EXISTS `feedback` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`user_id` INT(11) NOT NULL,
`response_id` INT(11) NOT NULL,
`vote_count` TINYINT(1) NOT NULL DEFAULT 0,
`create_time` TIMESTAMP NOT NULL DEFAULT 0,
`update_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
FOREIGN KEY (`response_id`) REFERENCES `response` (`id`) ON DELETE CASCADE,
FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE CASCADE,
UNIQUE no_duplicates(`user_id`, `response_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
SET foreign_key_checks = 1;