-
Notifications
You must be signed in to change notification settings - Fork 0
/
database.sql
49 lines (46 loc) · 1.61 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
CREATE TABLE `spaces`
(
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(200) NOT NULL,
`notes` text NOT NULL DEFAULT '',
PRIMARY KEY (`id`)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4;
CREATE TABLE `mealtypes`
(
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(200) NOT NULL,
`space` int(11) NOT NULL,
`notificationTime` time DEFAULT NULL,
PRIMARY KEY (`id`),
FOREIGN KEY (`space`) REFERENCES `spaces` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4;
CREATE TABLE `meals`
(
`id` int(11) NOT NULL AUTO_INCREMENT,
`date` DATE NOT NULL,
`text` varchar(200) NOT NULL,
`url` varchar(2048) DEFAULT NULL,
`type` int(11) NOT NULL,
`space` int(11) NOT NULL,
PRIMARY KEY (`id`),
FOREIGN KEY (`type`) REFERENCES `mealtypes` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY (`space`) REFERENCES `spaces` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
INDEX `space_date` (`space`, `date`),
INDEX `space_text` (`space`, `text`)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4;
CREATE TABLE `notifications`
(
`id` int(11) NOT NULL AUTO_INCREMENT,
`meal` int(11) NOT NULL,
`time` DATETIME NOT NULL,
`text` varchar(200) DEFAULT NULL,
`triggered` boolean NOT NULL DEFAULT false,
PRIMARY KEY (`id`),
FOREIGN KEY (`meal`) REFERENCES `meals` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
INDEX (`time`),
INDEX (`triggered`)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4;