Mercurial > dive4elements > river
comparison flys-backend/doc/schema/oracle.sql @ 3344:cb376f48dd37 2.8
merged flys-backend/2.8
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:36 +0200 |
parents | 790c12c55abb |
children | 3442304b430a |
comparison
equal
deleted
inserted
replaced
3318:dbe2f85bf160 | 3344:cb376f48dd37 |
---|---|
1 -- ANNOTATION_TYPES | |
2 CREATE SEQUENCE ANNOTATION_TYPES_ID_SEQ; | |
3 | |
4 CREATE TABLE annotation_types ( | |
5 id NUMBER(38,0) NOT NULL, | |
6 name VARCHAR2(255), | |
7 PRIMARY KEY (id) | |
8 ); | |
9 | |
10 | |
11 -- ANNOTATIONS | |
12 CREATE SEQUENCE ANNOTATIONS_ID_SEQ; | |
13 | |
14 CREATE TABLE annotations ( | |
15 id NUMBER(38,0) NOT NULL, | |
16 attribute_id NUMBER(38,0), | |
17 edge_id NUMBER(38,0), | |
18 position_id NUMBER(38,0), | |
19 range_id NUMBER(38,0), | |
20 type_id NUMBER(38,0), | |
21 PRIMARY KEY (id) | |
22 ); | |
23 | |
24 | |
25 -- ATTRIBUTES | |
26 CREATE SEQUENCE ATTRIBUTES_ID_SEQ; | |
27 | |
28 CREATE TABLE attributes ( | |
29 id NUMBER(38,0) NOT NULL, | |
30 value VARCHAR2(255), | |
31 primary key (id) | |
32 ); | |
33 | |
34 | |
35 -- CROSS_SECTION_LINES | |
36 CREATE SEQUENCE CROSS_SECTION_LINES_ID_SEQ; | |
37 | |
38 CREATE TABLE cross_section_lines ( | |
39 id NUMBER(38,0) NOT NULL, | |
40 km NUMBER(38,2), | |
41 cross_section_id NUMBER(38,0), | |
42 PRIMARY KEY (id) | |
43 ); | |
44 | |
45 | |
46 -- CROSS_SECTION_POINTS | |
47 CREATE SEQUENCE CROSS_SECTION_POINTS_ID_SEQ; | |
48 | |
49 CREATE TABLE cross_section_points ( | |
50 id NUMBER(38,0) NOT NULL, | |
51 col_pos NUMBER(38,0), | |
52 x NUMBER(38,2), | |
53 y NUMBER(38,2), | |
54 cross_section_line_id NUMBER(38,0), | |
55 PRIMARY KEY (id) | |
56 ); | |
57 | |
58 | |
59 -- CROSS_SECTIONS | |
60 CREATE SEQUENCE CROSS_SECTIONS_ID_SEQ; | |
61 | |
62 CREATE TABLE cross_sections ( | |
63 id NUMBER(38,0) NOT NULL, | |
64 description VARCHAR2(255), | |
65 river_id NUMBER(38,0), | |
66 time_interval_id NUMBER(38,0), | |
67 PRIMARY KEY (id) | |
68 ); | |
69 | |
70 -- Indices for faster access of the points | |
71 CREATE INDEX cross_section_lines_km_idx | |
72 ON cross_section_lines(km); | |
73 CREATE INDEX cross_section_points_line_idx | |
74 ON cross_section_points(cross_section_line_id); | |
75 | |
76 -- DISCHARGE_TABLE_VALUES | |
77 CREATE SEQUENCE DISCHARGE_TABLE_VALUES_ID_SEQ; | |
78 | |
79 CREATE TABLE discharge_table_values ( | |
80 id NUMBER(38,0) NOT NULL, | |
81 q NUMBER(38,2), | |
82 w NUMBER(38,2), | |
83 table_id NUMBER(38,0), | |
84 PRIMARY KEY (id) | |
85 ); | |
86 | |
87 | |
88 -- DISCHARGE_TABLES | |
89 CREATE SEQUENCE DISCHARGE_TABLES_ID_SEQ; | |
90 | |
91 CREATE TABLE discharge_tables ( | |
92 id NUMBER(38,0) NOT NULL, | |
93 description VARCHAR2(255), | |
94 kind NUMBER(38,0), | |
95 gauge_id NUMBER(38,0), | |
96 time_interval_id NUMBER(38,0), | |
97 PRIMARY KEY (id) | |
98 ); | |
99 | |
100 | |
101 -- EDGES | |
102 CREATE SEQUENCE EDGES_ID_SEQ; | |
103 | |
104 CREATE TABLE edges ( | |
105 id NUMBER(38,0) NOT NULL, | |
106 bottom NUMBER(38,2), | |
107 top NUMBER(38,2), | |
108 PRIMARY KEY (id) | |
109 ); | |
110 | |
111 | |
112 -- GAUGES | |
113 CREATE SEQUENCE GAUGES_ID_SEQ; | |
114 | |
115 CREATE TABLE gauges ( | |
116 id NUMBER(38,0) NOT NULL, | |
117 aeo NUMBER(38,2), | |
118 datum NUMBER(38,2), | |
119 name VARCHAR2(255), | |
120 station NUMBER(38,2), | |
121 official_number NUMBER(38,0), | |
122 range_id NUMBER(38,0), | |
123 river_id NUMBER(38,0), | |
124 PRIMARY KEY (id) | |
125 ); | |
126 | |
127 | |
128 -- HYK_ENTRIES | |
129 CREATE SEQUENCE HYK_ENTRIES_ID_SEQ; | |
130 | |
131 CREATE TABLE hyk_entries ( | |
132 id NUMBER(38,0) NOT NULL, | |
133 km NUMBER(38,2), | |
134 measure TIMESTAMP, | |
135 hyk_id NUMBER(38,0), | |
136 PRIMARY KEY (id) | |
137 ); | |
138 | |
139 | |
140 -- HYK_FLOW_ZONE_TYPES | |
141 CREATE SEQUENCE HYK_FLOW_ZONE_TYPES_ID_SEQ; | |
142 | |
143 CREATE TABLE hyk_flow_zone_types ( | |
144 id NUMBER(38,0) NOT NULL, | |
145 description VARCHAR2(255), | |
146 name VARCHAR2(255), | |
147 PRIMARY KEY (id) | |
148 ); | |
149 | |
150 | |
151 -- HYK_FLOW_ZONES | |
152 CREATE SEQUENCE HYK_FLOW_ZONES_ID_SEQ; | |
153 | |
154 CREATE TABLE hyk_flow_zones ( | |
155 id NUMBER(38,0) NOT NULL, | |
156 a NUMBER(38,2), | |
157 b NUMBER(38,2), | |
158 formation_id NUMBER(38,0), | |
159 type_id NUMBER(38,0), | |
160 primary key (id) | |
161 ); | |
162 | |
163 | |
164 -- HYK_FORMATIONS | |
165 CREATE SEQUENCE HYK_FORMATIONS_ID_SEQ; | |
166 | |
167 CREATE TABLE hyk_formations ( | |
168 id NUMBER(38,0) NOT NULL, | |
169 bottom NUMBER(38,2), | |
170 distance_hf NUMBER(38,2), | |
171 distance_vl NUMBER(38,2), | |
172 distance_vr NUMBER(38,2), | |
173 formation_num NUMBER(38,0), | |
174 top NUMBER(38,2), | |
175 hyk_entry_id NUMBER(38,0), | |
176 PRIMARY KEY (id) | |
177 ); | |
178 | |
179 | |
180 -- HYKS | |
181 CREATE SEQUENCE HYKS_ID_SEQ; | |
182 | |
183 CREATE TABLE hyks ( | |
184 id NUMBER(38,0) NOT NULL, | |
185 description VARCHAR2(255), | |
186 river_id NUMBER(38,0), | |
187 primary key (id) | |
188 ); | |
189 | |
190 | |
191 -- MAIN_VALUE_TYPES | |
192 CREATE SEQUENCE MAIN_VALUE_TYPES_ID_SEQ; | |
193 | |
194 CREATE TABLE main_value_types ( | |
195 id NUMBER(38,0) NOT NULL, | |
196 name VARCHAR2(255), | |
197 PRIMARY KEY (id) | |
198 ); | |
199 | |
200 | |
201 -- MAIN_VALUES | |
202 CREATE SEQUENCE MAIN_VALUES_ID_SEQ; | |
203 | |
204 CREATE TABLE main_values ( | |
205 id NUMBER(38,0) NOT NULL, | |
206 value NUMBER(38,2), | |
207 gauge_id NUMBER(38,0), | |
208 named_value_id NUMBER(38,0), | |
209 time_interval_id NUMBER(38,0), | |
210 PRIMARY KEY (id) | |
211 ); | |
212 | |
213 | |
214 -- NAMED_MAIN_VALUES | |
215 CREATE SEQUENCE NAMED_MAIN_VALUES_ID_SEQ; | |
216 | |
217 CREATE TABLE named_main_values ( | |
218 id NUMBER(38,0) NOT NULL, | |
219 name VARCHAR2(255), | |
220 type_id NUMBER(38,0), | |
221 PRIMARY KEY (id) | |
222 ); | |
223 | |
224 | |
225 -- POSITIONS | |
226 CREATE SEQUENCE POSITIONS_ID_SEQ; | |
227 | |
228 CREATE TABLE positions ( | |
229 id NUMBER(38,0) NOT NULL, | |
230 value VARCHAR2(255 char), | |
231 PRIMARY KEY (id) | |
232 ); | |
233 | |
234 | |
235 --- RANGES | |
236 CREATE SEQUENCE RANGES_ID_SEQ; | |
237 | |
238 CREATE TABLE ranges ( | |
239 id NUMBER(38,0) NOT NULL, | |
240 a NUMBER(38,10), | |
241 b NUMBER(38,10), | |
242 river_id NUMBER(38,0), | |
243 PRIMARY KEY (id) | |
244 ); | |
245 | |
246 | |
247 -- RIVERS | |
248 CREATE SEQUENCE RIVERS_ID_SEQ; | |
249 | |
250 CREATE TABLE rivers ( | |
251 id NUMBER(38,0) NOT NULL, | |
252 km_up NUMBER(38,0), | |
253 name VARCHAR2(255), | |
254 wst_unit_id NUMBER(38,0), | |
255 PRIMARY KEY (id) | |
256 ); | |
257 | |
258 | |
259 -- TIME_INTERVALS | |
260 CREATE SEQUENCE TIME_INTERVALS_ID_SEQ; | |
261 | |
262 CREATE TABLE time_intervals ( | |
263 id NUMBER(38,0) NOT NULL, | |
264 start_time TIMESTAMP, | |
265 stop_time TIMESTAMP, | |
266 PRIMARY KEY (id) | |
267 ); | |
268 | |
269 | |
270 --- UNITS | |
271 CREATE SEQUENCE UNITS_ID_SEQ; | |
272 | |
273 CREATE TABLE units ( | |
274 id NUMBER(38,0) NOT NULL, | |
275 name VARCHAR2(255), | |
276 PRIMARY KEY (id) | |
277 ); | |
278 | |
279 | |
280 -- WST_COLUMN_Q_RANGES | |
281 CREATE SEQUENCE WST_COLUMN_Q_RANGES_ID_SEQ; | |
282 | |
283 CREATE TABLE wst_column_q_ranges ( | |
284 id NUMBER(38,0) NOT NULL, | |
285 wst_column_id NUMBER(38,0), | |
286 wst_q_range_id NUMBER(38,0), | |
287 PRIMARY KEY (id) | |
288 ); | |
289 | |
290 | |
291 -- WST_COLUMN_VALUES | |
292 CREATE SEQUENCE WST_COLUMN_VALUES_ID_SEQ; | |
293 | |
294 CREATE TABLE wst_column_values ( | |
295 id NUMBER(38,0) NOT NULL, | |
296 position NUMBER(38,5), | |
297 w NUMBER(38,5), | |
298 wst_column_id NUMBER(38,0), | |
299 PRIMARY KEY (id) | |
300 ); | |
301 | |
302 | |
303 -- WST_COLUMNS | |
304 CREATE SEQUENCE WST_COLUMNS_ID_SEQ; | |
305 | |
306 CREATE TABLE wst_columns ( | |
307 id NUMBER(38,0) NOT NULL, | |
308 description VARCHAR2(255), | |
309 name VARCHAR2(255), | |
310 position NUMBER(38,0), | |
311 time_interval_id NUMBER(38,0), | |
312 wst_id NUMBER(38,0), | |
313 PRIMARY KEY (id) | |
314 ); | |
315 | |
316 | |
317 -- WST_Q_RANGES | |
318 CREATE SEQUENCE WST_Q_RANGES_ID_SEQ; | |
319 | |
320 CREATE TABLE wst_q_ranges ( | |
321 id NUMBER(38,0) NOT NULL, | |
322 q NUMBER(38,5), | |
323 range_id NUMBER(38,0), | |
324 PRIMARY KEY (id) | |
325 ); | |
326 | |
327 | |
328 -- WSTS | |
329 CREATE SEQUENCE WSTS_ID_SEQ; | |
330 | |
331 CREATE TABLE wsts ( | |
332 id NUMBER(38,0) NOT NULL, | |
333 description VARCHAR2(255), | |
334 kind NUMBER(38,0), | |
335 river_id NUMBER(38,0), | |
336 PRIMARY KEY (id) | |
337 ); | |
338 | |
339 | |
340 -- ADD CONSTRAINTs | |
341 ALTER TABLE annotations ADD CONSTRAINT cAnnotationsRanges FOREIGN KEY (range_id) REFERENCES ranges; | |
342 ALTER TABLE annotations ADD CONSTRAINT cAnnotationsEdges FOREIGN KEY (edge_id) REFERENCES edges; | |
343 ALTER TABLE annotations ADD CONSTRAINT cAnnotationsPositions FOREIGN KEY (position_id) REFERENCES positions; | |
344 ALTER TABLE annotations ADD CONSTRAINT cAnnotationsAttributes FOREIGN KEY (attribute_id) REFERENCES attributes; | |
345 ALTER TABLE annotations ADD CONSTRAINT cAnnotationsTypes FOREIGN KEY (type_id) REFERENCES annotation_types; | |
346 ALTER TABLE cross_section_lines ADD CONSTRAINT cQPSLinesCrossSections FOREIGN KEY (cross_section_id) REFERENCES cross_sections; | |
347 ALTER TABLE cross_section_points ADD CONSTRAINT cQPSPointsCrossSectionLines FOREIGN KEY (cross_section_line_id) REFERENCES cross_section_lines; | |
348 ALTER TABLE cross_sections ADD CONSTRAINT cCrossSectionsRivers FOREIGN KEY (river_id) REFERENCES rivers; | |
349 ALTER TABLE cross_sections ADD CONSTRAINT cCrossSectionsTimeIntervals FOREIGN KEY (time_interval_id) REFERENCES time_intervals; | |
350 ALTER TABLE discharge_table_values ADD CONSTRAINT cTableValuesDischargeTables foreign key (table_id) REFERENCES discharge_tables; | |
351 ALTER TABLE discharge_tables ADD CONSTRAINT cDischargeTablesTime_intervals FOREIGN KEY (time_interval_id) REFERENCES time_intervals; | |
352 ALTER TABLE discharge_tables ADD CONSTRAINT cDischargeTablesGauges FOREIGN KEY (gauge_id) REFERENCES gauges; | |
353 ALTER TABLE gauges ADD CONSTRAINT cGaugesRivers FOREIGN KEY (river_id) REFERENCES rivers; | |
354 ALTER TABLE gauges ADD CONSTRAINT cGaugesRanges FOREIGN KEY (range_id) REFERENCES ranges; | |
355 ALTER TABLE hyk_entries ADD CONSTRAINT cHykEntriesHyks FOREIGN KEY (hyk_id) REFERENCES hyks; | |
356 ALTER TABLE hyk_flow_zones ADD CONSTRAINT cHykFlowZonesHykFormations FOREIGN KEY (formation_id) REFERENCES hyk_formations; | |
357 ALTER TABLE hyk_flow_zones ADD CONSTRAINT cHykFlowZonesHykFlowZoneTypes FOREIGN KEY (type_id) REFERENCES hyk_flow_zone_types; | |
358 ALTER TABLE hyks ADD CONSTRAINT cHyksRivers FOREIGN KEY (river_id) REFERENCES rivers; | |
359 ALTER TABLE hyk_formations ADD CONSTRAINT cHykFormationsHykEntries FOREIGN KEY (hyk_entry_id) REFERENCES hyk_entries; | |
360 ALTER TABLE main_values ADD CONSTRAINT cMainValuesTimeIntervals FOREIGN KEY (time_interval_id) REFERENCES time_intervals; | |
361 ALTER TABLE main_values ADD CONSTRAINT cMainValuesGauges FOREIGN KEY (gauge_id) REFERENCES gauges; | |
362 ALTER TABLE main_values ADD CONSTRAINT cMainValuesNamedMainValues FOREIGN KEY (named_value_id) REFERENCES named_main_values; | |
363 ALTER TABLE named_main_values ADD CONSTRAINT cNamedMainValuesMainValueTypes FOREIGN KEY (type_id) REFERENCES main_value_types; | |
364 ALTER TABLE ranges ADD CONSTRAINT cRangesRivers FOREIGN KEY (river_id) REFERENCES rivers; | |
365 ALTER TABLE rivers ADD CONSTRAINT cRiversUnits FOREIGN KEY (wst_unit_id) REFERENCES units; | |
366 ALTER TABLE wst_column_q_ranges ADD CONSTRAINT cWstColumnQRangesWstColums FOREIGN KEY (wst_column_id) REFERENCES wst_columns; | |
367 ALTER TABLE wst_column_q_ranges ADD CONSTRAINT cWstColumnQRangesWstQRanges FOREIGN KEY (wst_q_range_id) REFERENCES wst_q_ranges; | |
368 ALTER TABLE wst_column_values ADD CONSTRAINT cWstColumnValuesWstColumns FOREIGN KEY (wst_column_id) REFERENCES wst_columns; | |
369 ALTER TABLE wst_columns ADD CONSTRAINT cWstColumnsTime_intervals FOREIGN KEY (time_interval_id) REFERENCES time_intervals; | |
370 ALTER TABLE wst_columns ADD CONSTRAINT cWstColumnsWsts FOREIGN KEY (wst_id) REFERENCES wsts; | |
371 ALTER TABLE wst_q_ranges ADD CONSTRAINT cWstQRangesRanges FOREIGN KEY (range_id) REFERENCES RANGES; | |
372 ALTER TABLE wsts ADD CONSTRAINT cWstsRivers FOREIGN KEY (river_id) REFERENCES rivers; | |
373 | |
374 -- VIEWS | |
375 | |
376 CREATE VIEW wst_value_table AS | |
377 SELECT wcv.position AS position, | |
378 w, | |
379 (SELECT q | |
380 FROM wst_column_q_ranges wcqr | |
381 JOIN wst_q_ranges wqr | |
382 ON wcqr.wst_q_range_id = wqr.id | |
383 JOIN ranges r | |
384 ON r.id = wqr.range_id | |
385 WHERE wcqr.wst_column_id = wc.id | |
386 AND wcv.position BETWEEN r.a AND r.b) AS q, | |
387 wc.position AS column_pos, | |
388 w.id AS wst_id | |
389 FROM wst_column_values wcv | |
390 JOIN wst_columns wc | |
391 ON wcv.wst_column_id = wc.id | |
392 JOIN wsts w | |
393 ON wc.wst_id = w.id | |
394 ORDER BY wcv.position ASC, | |
395 wc.position DESC; | |
396 | |
397 -- view to select the w values of a WST | |
398 CREATE VIEW wst_w_values AS | |
399 SELECT wcv.position AS km, | |
400 wcv.w AS w, | |
401 wc.position AS column_pos, | |
402 w.id AS wst_id | |
403 FROM wst_column_values wcv | |
404 JOIN wst_columns wc ON wcv.wst_column_id = wc.id | |
405 JOIN wsts w ON wc.wst_id = w.id | |
406 ORDER BY wcv.position, wc.position; | |
407 | |
408 -- view to select the q values of a WST | |
409 CREATE VIEW wst_q_values AS | |
410 SELECT wc.position AS column_pos, | |
411 wqr.q AS q, | |
412 r.a AS a, | |
413 r.b AS b, | |
414 wc.wst_id AS wst_id | |
415 FROM wst_column_q_ranges wcqr | |
416 JOIN wst_q_ranges wqr ON wcqr.wst_q_range_id = wqr.id | |
417 JOIN ranges r ON wqr.range_id = r.id | |
418 JOIN wst_columns wc ON wcqr.wst_column_id = wc.id | |
419 ORDER BY wc.position, wcqr.wst_column_id, r.a; | |
420 | |
421 -- Views to make the 'Amtlichen Linien' easier to access. | |
422 | |
423 CREATE VIEW official_lines | |
424 AS | |
425 SELECT w.river_id AS river_id, | |
426 w.id AS wst_id, | |
427 wc.id AS wst_column_id, | |
428 wc.name AS name | |
429 FROM wsts w | |
430 JOIN wst_columns wc | |
431 ON wc.wst_id = w.id | |
432 WHERE w.kind = 3; | |
433 | |
434 CREATE VIEW q_main_values | |
435 AS | |
436 SELECT riv.id AS river_id, | |
437 g.id AS gauge_id, | |
438 g.name AS gauge_name, | |
439 r.a AS a, | |
440 r.b AS b, | |
441 REGEXP_REPLACE( | |
442 nmv.name, '[:space:]*\(.*\)[:space:]*', '') AS name, | |
443 CAST(mv.value AS NUMERIC(38, 5)) AS value | |
444 FROM main_values mv | |
445 JOIN named_main_values nmv | |
446 ON mv.named_value_id = nmv.id | |
447 JOIN main_value_types mvt | |
448 ON nmv.type_id = mvt.id | |
449 JOIN gauges g | |
450 ON mv.gauge_id = g.id | |
451 JOIN ranges r | |
452 ON g.range_id = r.id | |
453 JOIN rivers riv | |
454 ON g.river_id = riv.id | |
455 WHERE mvt.name = 'Q' | |
456 ORDER BY g.id, CAST(mv.value AS NUMERIC(38,5)); | |
457 | |
458 CREATE VIEW official_q_values | |
459 AS | |
460 SELECT ol.river_id AS river_id, | |
461 wst_id, | |
462 wst_column_id, | |
463 gauge_id, | |
464 gauge_name, | |
465 a, | |
466 b, | |
467 ol.name, | |
468 value | |
469 FROM official_lines ol | |
470 JOIN q_main_values qmv | |
471 ON ol.river_id = qmv.river_id | |
472 AND ol.name = qmv.name; |