-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase.sql
executable file
·56 lines (49 loc) · 1.99 KB
/
database.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
CREATE DATABASE IF NOT EXISTS `monkey`;
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION;
SET time_zone = "+00:00";
CREATE TABLE `monkey`.`login` (
`user_id` INT(12) NOT NULL AUTO_INCREMENT,
`username` VARCHAR(65535) NOT NULL,
`password` VARCHAR(65535) NOT NULL,
`salt1` TEXT NOT NULL,
`salt2` TEXT NOT NULL,
PRIMARY KEY (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE `monkey`.`forms` (
`form_id` INT(12) NOT NULL AUTO_INCREMENT,
`creator_username` VARCHAR(65535) NOT NULL,
`title` VARCHAR(65535) NOT NULL,
`description` VARCHAR(65535) NOT NULL,
`creation_date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`last_modified_date` TIMESTAMP on update CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`status` TEXT NOT NULL,
`response_count` INT NOT NULL,
PRIMARY KEY (`form_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE `monkey`.`fields` (
`field_id` INT(12) NOT NULL AUTO_INCREMENT,
`form_id` INT(12) NOT NULL,
`field_label` VARCHAR(65535) NOT NULL,
`field_type` VARCHAR(50) NOT NULL,
PRIMARY KEY (`field_id`),
FOREIGN KEY (`form_id`) REFERENCES `forms`(`form_id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE `monkey`.`responses` (
`response_id` INT(12) NOT NULL AUTO_INCREMENT,
`form_id` INT(12) NOT NULL,
`user_id` INT(12) NOT NULL,
`submitted_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`response_id`),
FOREIGN KEY (`form_id`) REFERENCES `forms`(`form_id`) ON DELETE CASCADE,
FOREIGN KEY (`user_id`) REFERENCES `login`(`user_id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE `monkey`.`response_data` (
`response_id` INT(12) NOT NULL,
`field_id` INT(12) NOT NULL,
`user_input` TEXT NOT NULL,
PRIMARY KEY (`response_id`, `field_id`),
FOREIGN KEY (`response_id`) REFERENCES `responses`(`response_id`) ON DELETE CASCADE,
FOREIGN KEY (`field_id`) REFERENCES `fields`(`field_id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
COMMIT;