-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path00-init.sql
72 lines (62 loc) · 1.68 KB
/
00-init.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
Create initial schema
*/
-- Table "station"
BEGIN;
CREATE TABLE station (
label TEXT PRIMARY KEY
);
COMMENT ON TABLE station IS 'Table for station-level information';
INSERT INTO station (label)
VALUES
('Hbf (Train)'),
('ZOB (Bus)'),
('Suedkreuz (Bus)'),
('Ostbahnhof (Train)');
-- Table "coordinator"
CREATE TABLE coordinator (
name TEXT,
station TEXT,
contact TEXT,
ts_start TIMESTAMP WITHOUT TIME ZONE,
ts_end TIMESTAMP WITHOUT TIME ZONE,
role TEXT,
tasks TEXT,
comment TEXT,
PRIMARY KEY(name, station, contact, ts_start),
CONSTRAINT
fk_coordinator_station FOREIGN KEY(station) REFERENCES station(label) ON UPDATE CASCADE
);
COMMENT ON TABLE coordinator IS 'Table on coordinators per station';
-- Table "volunteer"
CREATE TABLE volunteer (
name TEXT,
station TEXT,
contact TEXT,
ts_start TIMESTAMP WITHOUT TIME ZONE,
ts_end TIMESTAMP WITHOUT TIME ZONE,
share_contact BOOLEAN DEFAULT FALSE,
languages JSONB,
comment TEXT,
PRIMARY KEY (name, station, contact, ts_start),
CONSTRAINT
fk_volunteer_station FOREIGN KEY(station) REFERENCES station(label) ON UPDATE CASCADE
);
COMMENT ON TABLE volunteer IS 'Table of registered volunteers';
-- TABLE "incoming"
CREATE TABLE incoming (
station TEXT,
id TEXT,
platform INT DEFAULT NULL,
ts_scheduled TIMESTAMP WITHOUT TIME ZONE,
ts_estimated TIMESTAMP WITHOUT TIME ZONE,
delay INT,
ts_delay TIMESTAMP WITHOUT TIME ZONE DEFAULT NULL,
type TEXT,
passengers INT,
PRIMARY KEY (station, id, ts_scheduled),
CONSTRAINT
fk_incoming_station FOREIGN KEY(station) REFERENCES station(label) ON UPDATE CASCADE
);
COMMENT ON TABLE incoming IS 'Table on incoming trains and buses';
COMMIT;