-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdbschema.sql
More file actions
26 lines (24 loc) · 959 Bytes
/
dbschema.sql
File metadata and controls
26 lines (24 loc) · 959 Bytes
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
CREATE TABLE `users` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`class` varchar(255) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `sensors` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`userid` int(11) unsigned NOT NULL,
PRIMARY KEY (`id`),
KEY `userid` (`userid`),
CONSTRAINT `sensors_ibfk_1` FOREIGN KEY (`userid`) REFERENCES `users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `sensordata` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`data` decimal(16,8) NOT NULL,
`timestamp` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`sensorid` int(11) unsigned NOT NULL,
PRIMARY KEY (`id`),
KEY `sensorid` (`sensorid`),
CONSTRAINT `sensordata_ibfk_1` FOREIGN KEY (`sensorid`) REFERENCES `sensors` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;