-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.sql
183 lines (163 loc) · 5.58 KB
/
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
CREATE SCHEMA IF NOT EXISTS nrod;
-- Train Describer Data
-- C Class data
CREATE TABLE IF NOT EXISTS nrod.td_c (
time timestamptz,
area_id text,
msg_type text,
from_berth text,
to_berth text,
descr text
);
CREATE INDEX ON nrod.td_c(area_id);
-- S Class data
CREATE TABLE IF NOT EXISTS nrod.td_s (
time timestamptz,
area_id text,
bit smallint,
state boolean
);
CREATE INDEX ON nrod.td_s(area_id);
-- Train Movements: data from Network Rail's TRUST system
-- 0001 Train Activation
CREATE TABLE IF NOT EXISTS nrod.activation(
id integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
train_id text,
creation_timestamp timestamptz,
train_call_mode text,
train_call_type text,
train_service_code integer,
toc_id smallint,
sched_origin_stanox integer,
origin_dep_timestamp timestamptz,
tp_origin_stanox integer,
schedule_source text,
train_uid text,
schedule_start_date date,
schedule_end_date date,
schedule_type text
);
CREATE INDEX ON nrod.activation(train_id);
-- 0002 Train Cancellation
CREATE TABLE IF NOT EXISTS nrod.cancellation(
id integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
train_id text,
canx_timestamp timestamptz,
canx_type text,
canx_reason_code text,
loc_stanox integer,
dep_timestamp timestamptz,
orig_loc_stanox integer,
orig_loc_timestamp timestamptz,
original_data_source text
);
CREATE INDEX ON nrod.cancellation(train_id);
-- 0003 Train Movement
CREATE TABLE IF NOT EXISTS nrod.movement(
id integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
train_id text,
current_train_id text,
loc_stanox integer,
actual_timestamp timestamptz,
event_type text,
platform text,
planned_timestamp timestamptz,
timetable_variation smallint,
offroute_ind boolean,
original_data_source text
);
CREATE INDEX ON nrod.movement(train_id);
CREATE INDEX ON nrod.movement(planned_timestamp);
-- 0005 Train Reinstatement
CREATE TABLE IF NOT EXISTS nrod.reinstatement(
id integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
train_id text,
current_train_id text,
reinstatement_timestamp timestamptz,
loc_stanox integer,
dep_timestamp timestamptz,
original_loc_stanox integer,
original_loc_timestamp timestamptz,
original_data_source text
);
CREATE INDEX ON nrod.reinstatement(train_id);
-- 0006 Change of Origin
CREATE TABLE IF NOT EXISTS nrod.change_origin(
id integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
train_id text,
current_train_id text,
coo_timestamp timestamptz,
reason_code text,
loc_stanox integer,
dep_timestamp timestamptz,
original_loc_stanox integer,
original_loc_timestamp timestamptz,
original_data_source text
);
CREATE INDEX ON nrod.change_origin(train_id);
-- 0007 Change of Identity
CREATE TABLE IF NOT EXISTS nrod.change_identity(
id integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
train_id text,
current_train_id text,
revised_train_id text,
event_timestamp timestamptz,
original_data_source text
);
CREATE INDEX ON nrod.change_identity(train_id);
-- 0008 Change of Location
CREATE TABLE IF NOT EXISTS nrod.change_location(
id integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
train_id text,
current_train_id text,
event_timestamp timestamptz,
loc_stanox integer,
dep_timestamp timestamptz,
original_loc_stanox integer,
original_loc_timestamp timestamptz,
original_data_source text
);
CREATE INDEX ON nrod.change_location(train_id);
-- TSR Feed
-- Headers of the TSR message
CREATE TABLE IF NOT EXISTS nrod.tsr_batch_msg(
id integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
route_group text,
route_group_code text,
publish_date timestamptz,
publish_source text,
route_group_coverage text,
batch_publish_event text,
won_start_date timestamptz,
won_end_date timestamptz
);
-- Temporary Speed Restrictions
CREATE TABLE IF NOT EXISTS nrod.tsr(
tsr_batch_msg_id int REFERENCES nrod.tsr_batch_msg(id) ON DELETE CASCADE,
tsrid int,
creation_date timestamptz,
publish_date timestamptz,
publish_event text,
route_group text,
route_code text,
route_order smallint,
tsr_reference text,
from_location text,
to_location text,
line_name text,
subunit_type text,
mileage_from smallint,
subunit_from smallint,
mileage_to smallint,
subunit_to smallint,
moving_mileage boolean,
passenger_speed smallint,
freight_speed smallint,
valid_from_date timestamptz,
valid_to_date timestamptz,
reason text,
requestor text,
comments text,
direction text,
PRIMARY KEY (tsr_batch_msg_id, tsrid)
);