-
Notifications
You must be signed in to change notification settings - Fork 1
/
schema.pgsql
49 lines (43 loc) · 1.27 KB
/
schema.pgsql
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
-- in reverse order because of FOREIGN KEYs
DROP TABLE IF EXISTS team_location_history;
DROP TABLE IF EXISTS cipher_status;
DROP TABLE IF EXISTS team_status;
DROP TABLE IF EXISTS messages;
CREATE TABLE team_status (
team text PRIMARY KEY,
lat float NOT NULL,
lon float NOT NULL,
last_moved timestamptz DEFAULT NULL,
cooldown_to timestamptz DEFAULT NULL
);
CREATE TABLE cipher_status (
cipher text NOT NULL,
team text NOT NULL,
arrival timestamptz NOT NULL,
solved timestamptz DEFAULT NULL,
hint timestamptz DEFAULT NULL,
skip timestamptz DEFAULT NULL,
extra_points int DEFAULT 0,
hint_score int DEFAULT 0,
UNIQUE (cipher, team),
FOREIGN KEY(team) REFERENCES team_status(team) ON DELETE CASCADE
);
CREATE TABLE team_location_history (
team text NOT NULL,
time timestamptz DEFAULT CURRENT_TIMESTAMP,
lat float NOT NULL,
lon float NOT NULL,
FOREIGN KEY(team) REFERENCES team_status(team) ON DELETE CASCADE
);
CREATE TABLE messages (
id SERIAL PRIMARY KEY,
team text NOT NULL,
cipher text NOT NULL,
time timestamptz DEFAULT CURRENT_TIMESTAMP,
phone_number text NOT NULL,
sms_id integer NOT NULL,
text text NOT NULL,
response text NOT NULL
);
CREATE INDEX messages_sms_id ON messages(sms_id);
CREATE INDEX messages_team ON messages(team);