-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreation_script.sql
More file actions
33 lines (28 loc) · 900 Bytes
/
Copy pathcreation_script.sql
File metadata and controls
33 lines (28 loc) · 900 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
27
28
29
30
31
32
33
CREATE TABLE rooms(
ID serial PRIMARY KEY ,
name CHAR(255) NOT NULL,
);
CREATE TABLE sensors(
ID serial PRIMARY KEY ,
name CHAR(255) NOT NULL,
roomID INT NOT NULL
);
CREATE TABLE presences(
ID serial PRIMARY KEY ,
MAC CHAR(255) NOT NULL,
lastDetected TIMESTAMP NOT NULL,
active BOOLEAN NOT NULL,
roomID INT NOT NULL
);
ALTER TABLE sensors
ADD CONSTRAINT roomID
FOREIGN KEY (roomID)
REFERENCES rooms (ID);
ALTER TABLE presences
ADD CONSTRAINT roomID
FOREIGN KEY (roomID)
REFERENCES rooms (ID);
CREATE UNIQUE INDEX sensors_name_room
ON sensors (name, roomid);
CREATE UNIQUE INDEX room_name
ON rooms (name);