Mercurial > gemma
annotate wamos.sql @ 84:d905022a48e9
More user attributes from APUC3.
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Fri, 01 Jun 2018 16:14:40 +0200 |
parents | d9d01dc58f60 |
children | 1a640da943b6 |
rev | line source |
---|---|
35
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
1 BEGIN; |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
2 |
81
acaa485c0c1e
Use different schemas for different diagrams. Add TODOs.
Tom Gottfried <tom@intevation.de>
parents:
80
diff
changeset
|
3 -- |
acaa485c0c1e
Use different schemas for different diagrams. Add TODOs.
Tom Gottfried <tom@intevation.de>
parents:
80
diff
changeset
|
4 -- Infrastructure |
acaa485c0c1e
Use different schemas for different diagrams. Add TODOs.
Tom Gottfried <tom@intevation.de>
parents:
80
diff
changeset
|
5 -- |
35
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
6 CREATE EXTENSION postgis; |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
7 |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
8 CREATE FUNCTION update_date_info() RETURNS trigger |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
9 LANGUAGE plpgsql |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
10 AS $$ |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
11 BEGIN |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
12 NEW.date_info = CURRENT_TIMESTAMP; |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
13 RETURN NEW; |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
14 END; |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
15 $$; |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
16 |
37
6f273a649f08
Be more specific with ISRS and update some comments.
Tom Gottfried <tom@intevation.de>
parents:
35
diff
changeset
|
17 -- Composite type: UN/LOCODE, fairway section, object reference, hectometre. |
6f273a649f08
Be more specific with ISRS and update some comments.
Tom Gottfried <tom@intevation.de>
parents:
35
diff
changeset
|
18 -- See RIS-Index Encoding Guide |
35
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
19 CREATE TYPE isrs AS ( |
37
6f273a649f08
Be more specific with ISRS and update some comments.
Tom Gottfried <tom@intevation.de>
parents:
35
diff
changeset
|
20 country_code char(2), -- ISO 3166 country code |
6f273a649f08
Be more specific with ISRS and update some comments.
Tom Gottfried <tom@intevation.de>
parents:
35
diff
changeset
|
21 -- could be validated against countries table. |
6f273a649f08
Be more specific with ISRS and update some comments.
Tom Gottfried <tom@intevation.de>
parents:
35
diff
changeset
|
22 locode char(3), -- without the country code: |
6f273a649f08
Be more specific with ISRS and update some comments.
Tom Gottfried <tom@intevation.de>
parents:
35
diff
changeset
|
23 -- http://www.unece.org/cefact/locode/welcome.html |
6f273a649f08
Be more specific with ISRS and update some comments.
Tom Gottfried <tom@intevation.de>
parents:
35
diff
changeset
|
24 fairway_section char(5), |
6f273a649f08
Be more specific with ISRS and update some comments.
Tom Gottfried <tom@intevation.de>
parents:
35
diff
changeset
|
25 object_reference char(5), |
6f273a649f08
Be more specific with ISRS and update some comments.
Tom Gottfried <tom@intevation.de>
parents:
35
diff
changeset
|
26 hectometre int -- should be constrained to five digits |
6f273a649f08
Be more specific with ISRS and update some comments.
Tom Gottfried <tom@intevation.de>
parents:
35
diff
changeset
|
27 ); |
35
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
28 |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
29 CREATE TYPE isrsrange AS RANGE ( |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
30 subtype = isrs |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
31 ); |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
32 |
81
acaa485c0c1e
Use different schemas for different diagrams. Add TODOs.
Tom Gottfried <tom@intevation.de>
parents:
80
diff
changeset
|
33 -- |
acaa485c0c1e
Use different schemas for different diagrams. Add TODOs.
Tom Gottfried <tom@intevation.de>
parents:
80
diff
changeset
|
34 -- WAMOS data |
acaa485c0c1e
Use different schemas for different diagrams. Add TODOs.
Tom Gottfried <tom@intevation.de>
parents:
80
diff
changeset
|
35 -- |
acaa485c0c1e
Use different schemas for different diagrams. Add TODOs.
Tom Gottfried <tom@intevation.de>
parents:
80
diff
changeset
|
36 CREATE SCHEMA wamos; |
acaa485c0c1e
Use different schemas for different diagrams. Add TODOs.
Tom Gottfried <tom@intevation.de>
parents:
80
diff
changeset
|
37 CREATE SCHEMA wamos_waterway; |
acaa485c0c1e
Use different schemas for different diagrams. Add TODOs.
Tom Gottfried <tom@intevation.de>
parents:
80
diff
changeset
|
38 CREATE SCHEMA wamos_fairway; |
acaa485c0c1e
Use different schemas for different diagrams. Add TODOs.
Tom Gottfried <tom@intevation.de>
parents:
80
diff
changeset
|
39 SET search_path TO public, wamos, wamos_waterway, wamos_fairway; |
acaa485c0c1e
Use different schemas for different diagrams. Add TODOs.
Tom Gottfried <tom@intevation.de>
parents:
80
diff
changeset
|
40 |
acaa485c0c1e
Use different schemas for different diagrams. Add TODOs.
Tom Gottfried <tom@intevation.de>
parents:
80
diff
changeset
|
41 -- |
83 | 42 -- Auxiliary tables |
81
acaa485c0c1e
Use different schemas for different diagrams. Add TODOs.
Tom Gottfried <tom@intevation.de>
parents:
80
diff
changeset
|
43 -- |
82 | 44 CREATE TABLE wamos.system_config ( |
45 config_key varchar PRIMARY KEY, | |
46 config_val varchar | |
47 ); | |
81
acaa485c0c1e
Use different schemas for different diagrams. Add TODOs.
Tom Gottfried <tom@intevation.de>
parents:
80
diff
changeset
|
48 |
82 | 49 CREATE TABLE wamos.countries ( |
50 country_code char(2) PRIMARY KEY -- ISO 3166 country code | |
51 -- A smallint PK would require even less disk space i.e. on the FK side. | |
52 -- This might be an issue in case cache space becomes a limiting | |
53 -- factor when there are many FKs pointing here. | |
54 ); | |
55 | |
56 CREATE TABLE wamos.responsibility_areas ( | |
57 country char(2) PRIMARY KEY REFERENCES countries, | |
58 area geometry(POLYGON, 4326) | |
59 ); | |
81
acaa485c0c1e
Use different schemas for different diagrams. Add TODOs.
Tom Gottfried <tom@intevation.de>
parents:
80
diff
changeset
|
60 |
84
d905022a48e9
More user attributes from APUC3.
Tom Gottfried <tom@intevation.de>
parents:
83
diff
changeset
|
61 CREATE TABLE wamos.languages ( |
d905022a48e9
More user attributes from APUC3.
Tom Gottfried <tom@intevation.de>
parents:
83
diff
changeset
|
62 language_code varchar PRIMARY KEY |
d905022a48e9
More user attributes from APUC3.
Tom Gottfried <tom@intevation.de>
parents:
83
diff
changeset
|
63 ); |
d905022a48e9
More user attributes from APUC3.
Tom Gottfried <tom@intevation.de>
parents:
83
diff
changeset
|
64 |
82 | 65 CREATE TABLE wamos.user_profiles ( |
66 username varchar PRIMARY KEY, -- TODO: check it's in pg_roles by trigger | |
84
d905022a48e9
More user attributes from APUC3.
Tom Gottfried <tom@intevation.de>
parents:
83
diff
changeset
|
67 country char(2) NOT NULL REFERENCES countries, |
d905022a48e9
More user attributes from APUC3.
Tom Gottfried <tom@intevation.de>
parents:
83
diff
changeset
|
68 language_code varchar REFERENCES languages, |
d905022a48e9
More user attributes from APUC3.
Tom Gottfried <tom@intevation.de>
parents:
83
diff
changeset
|
69 map_extent box2d, |
82 | 70 email_adress varchar NOT NULL UNIQUE |
71 ); | |
72 | |
73 CREATE TABLE wamos.templates ( | |
74 id int PRIMARY KEY, | |
75 dummy_attrib varchar, | |
76 "..." varchar | |
77 -- TODO: template attributes tbd. | |
78 ); | |
79 | |
80 CREATE TABLE wamos.user_templates ( | |
81 username varchar NOT NULL REFERENCES user_profiles, | |
82 template_id int NOT NULL REFERENCES templates, | |
83 PRIMARY KEY (username, template_id) | |
84 ); | |
85 | |
86 -- | |
87 -- General river information | |
88 -- | |
81
acaa485c0c1e
Use different schemas for different diagrams. Add TODOs.
Tom Gottfried <tom@intevation.de>
parents:
80
diff
changeset
|
89 |
53 | 90 -- Eventually obsolete. |
91 -- See https://roundup-intern.intevation.de/wamos/issue5 | |
62
39e0e3d8dd1b
Comment potentially obsolete table out.
Tom Gottfried <tom@intevation.de>
parents:
60
diff
changeset
|
92 -- CREATE TABLE rwdrs ( |
39e0e3d8dd1b
Comment potentially obsolete table out.
Tom Gottfried <tom@intevation.de>
parents:
60
diff
changeset
|
93 -- stretch isrsrange PRIMARY KEY, |
39e0e3d8dd1b
Comment potentially obsolete table out.
Tom Gottfried <tom@intevation.de>
parents:
60
diff
changeset
|
94 -- -- https://www.postgresql.org/docs/10/static/sql-createindex.html: |
39e0e3d8dd1b
Comment potentially obsolete table out.
Tom Gottfried <tom@intevation.de>
parents:
60
diff
changeset
|
95 -- -- Only B-tree supports UNIQUE indexes, but we need the GIST index |
39e0e3d8dd1b
Comment potentially obsolete table out.
Tom Gottfried <tom@intevation.de>
parents:
60
diff
changeset
|
96 -- -- below anyhow. |
39e0e3d8dd1b
Comment potentially obsolete table out.
Tom Gottfried <tom@intevation.de>
parents:
60
diff
changeset
|
97 -- -- Is it a good idea to build B-tree indexes on relatively large |
39e0e3d8dd1b
Comment potentially obsolete table out.
Tom Gottfried <tom@intevation.de>
parents:
60
diff
changeset
|
98 -- -- composites of string values or should we use inter PKs? |
39e0e3d8dd1b
Comment potentially obsolete table out.
Tom Gottfried <tom@intevation.de>
parents:
60
diff
changeset
|
99 -- -- => In case the index is used and cache space becomes a limiting |
39e0e3d8dd1b
Comment potentially obsolete table out.
Tom Gottfried <tom@intevation.de>
parents:
60
diff
changeset
|
100 -- -- factor, this might be an issue. |
39e0e3d8dd1b
Comment potentially obsolete table out.
Tom Gottfried <tom@intevation.de>
parents:
60
diff
changeset
|
101 -- rwdr double precision NOT NULL, |
39e0e3d8dd1b
Comment potentially obsolete table out.
Tom Gottfried <tom@intevation.de>
parents:
60
diff
changeset
|
102 -- EXCLUDE USING GIST (stretch WITH &&) |
39e0e3d8dd1b
Comment potentially obsolete table out.
Tom Gottfried <tom@intevation.de>
parents:
60
diff
changeset
|
103 -- ); |
35
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
104 |
81
acaa485c0c1e
Use different schemas for different diagrams. Add TODOs.
Tom Gottfried <tom@intevation.de>
parents:
80
diff
changeset
|
105 CREATE TABLE wamos_waterway.waterway_area ( |
69 | 106 dummy_attrib varchar, |
107 "..." varchar | |
108 -- TODO: add real waterway area attributes (DRC 2.1.3) | |
109 ); | |
110 | |
81
acaa485c0c1e
Use different schemas for different diagrams. Add TODOs.
Tom Gottfried <tom@intevation.de>
parents:
80
diff
changeset
|
111 CREATE TABLE wamos_fairway.reference_water_levels ( |
70
28108455ad35
Add reference water levels to gauges.
Tom Gottfried <tom@intevation.de>
parents:
69
diff
changeset
|
112 reference_water_level varchar(20) PRIMARY KEY |
28108455ad35
Add reference water levels to gauges.
Tom Gottfried <tom@intevation.de>
parents:
69
diff
changeset
|
113 ); |
28108455ad35
Add reference water levels to gauges.
Tom Gottfried <tom@intevation.de>
parents:
69
diff
changeset
|
114 |
81
acaa485c0c1e
Use different schemas for different diagrams. Add TODOs.
Tom Gottfried <tom@intevation.de>
parents:
80
diff
changeset
|
115 CREATE TABLE wamos_fairway.gauges ( |
38
529319bc3c5b
Mark gauges table as placeholder.
Tom Gottfried <tom@intevation.de>
parents:
37
diff
changeset
|
116 location isrs PRIMARY KEY, |
43 | 117 dummy_attrib varchar, |
118 "..." varchar | |
38
529319bc3c5b
Mark gauges table as placeholder.
Tom Gottfried <tom@intevation.de>
parents:
37
diff
changeset
|
119 -- TODO: add real gauge attributes (DRC 2.1.4) |
35
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
120 ); |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
121 |
81
acaa485c0c1e
Use different schemas for different diagrams. Add TODOs.
Tom Gottfried <tom@intevation.de>
parents:
80
diff
changeset
|
122 CREATE TABLE wamos_fairway.gauges_reference_water_levels ( |
71
e9bc0d93bef9
Add missing NOT NULL constraints.
Tom Gottfried <tom@intevation.de>
parents:
70
diff
changeset
|
123 gauge_id isrs NOT NULL REFERENCES gauges, |
e9bc0d93bef9
Add missing NOT NULL constraints.
Tom Gottfried <tom@intevation.de>
parents:
70
diff
changeset
|
124 reference_water_level varchar(20) |
e9bc0d93bef9
Add missing NOT NULL constraints.
Tom Gottfried <tom@intevation.de>
parents:
70
diff
changeset
|
125 NOT NULL REFERENCES reference_water_levels, |
70
28108455ad35
Add reference water levels to gauges.
Tom Gottfried <tom@intevation.de>
parents:
69
diff
changeset
|
126 PRIMARY KEY (gauge_id, reference_water_level), |
28108455ad35
Add reference water levels to gauges.
Tom Gottfried <tom@intevation.de>
parents:
69
diff
changeset
|
127 value int NOT NULL |
28108455ad35
Add reference water levels to gauges.
Tom Gottfried <tom@intevation.de>
parents:
69
diff
changeset
|
128 ); |
28108455ad35
Add reference water levels to gauges.
Tom Gottfried <tom@intevation.de>
parents:
69
diff
changeset
|
129 |
81
acaa485c0c1e
Use different schemas for different diagrams. Add TODOs.
Tom Gottfried <tom@intevation.de>
parents:
80
diff
changeset
|
130 CREATE TABLE wamos_fairway.gauge_measurements ( |
72
158f776732c7
Add gauge measurements stub.
Tom Gottfried <tom@intevation.de>
parents:
71
diff
changeset
|
131 fk_gauge_id isrs NOT NULL REFERENCES gauges, |
158f776732c7
Add gauge measurements stub.
Tom Gottfried <tom@intevation.de>
parents:
71
diff
changeset
|
132 -- XXX: Is country_code really relevant for WAMOS or just NtS? |
158f776732c7
Add gauge measurements stub.
Tom Gottfried <tom@intevation.de>
parents:
71
diff
changeset
|
133 -- country_code char(2) NOT NULL REFERENCES countries, |
158f776732c7
Add gauge measurements stub.
Tom Gottfried <tom@intevation.de>
parents:
71
diff
changeset
|
134 -- TODO: add relations to stuff provided as enumerations |
158f776732c7
Add gauge measurements stub.
Tom Gottfried <tom@intevation.de>
parents:
71
diff
changeset
|
135 dummy_attrib varchar, |
158f776732c7
Add gauge measurements stub.
Tom Gottfried <tom@intevation.de>
parents:
71
diff
changeset
|
136 "..." varchar |
158f776732c7
Add gauge measurements stub.
Tom Gottfried <tom@intevation.de>
parents:
71
diff
changeset
|
137 -- TODO: add real gauge measurement attributes (DRC 2.1.5) |
158f776732c7
Add gauge measurements stub.
Tom Gottfried <tom@intevation.de>
parents:
71
diff
changeset
|
138 ); |
158f776732c7
Add gauge measurements stub.
Tom Gottfried <tom@intevation.de>
parents:
71
diff
changeset
|
139 |
81
acaa485c0c1e
Use different schemas for different diagrams. Add TODOs.
Tom Gottfried <tom@intevation.de>
parents:
80
diff
changeset
|
140 CREATE TABLE wamos_waterway.waterway_axis ( |
73 | 141 dummy_attrib varchar, |
142 "..." varchar | |
143 -- TODO: add real waterway area attributes (DRC 2.1.3) | |
144 ); | |
145 | |
81
acaa485c0c1e
Use different schemas for different diagrams. Add TODOs.
Tom Gottfried <tom@intevation.de>
parents:
80
diff
changeset
|
146 CREATE TABLE wamos_waterway.distance_mark_functions ( |
78
012948f18faa
Distance marks as link between 1D and 2D.
Tom Gottfried <tom@intevation.de>
parents:
77
diff
changeset
|
147 -- XXX: Redundant information to object code in isrs code of dist. mark |
012948f18faa
Distance marks as link between 1D and 2D.
Tom Gottfried <tom@intevation.de>
parents:
77
diff
changeset
|
148 distance_mark_function varchar(8) PRIMARY KEY |
012948f18faa
Distance marks as link between 1D and 2D.
Tom Gottfried <tom@intevation.de>
parents:
77
diff
changeset
|
149 ); |
012948f18faa
Distance marks as link between 1D and 2D.
Tom Gottfried <tom@intevation.de>
parents:
77
diff
changeset
|
150 |
012948f18faa
Distance marks as link between 1D and 2D.
Tom Gottfried <tom@intevation.de>
parents:
77
diff
changeset
|
151 -- This table allows linkage between the 1D ISRS location codes and 2D space |
012948f18faa
Distance marks as link between 1D and 2D.
Tom Gottfried <tom@intevation.de>
parents:
77
diff
changeset
|
152 -- e.g. for cutting bottleneck area out of waterway area based on virtual |
012948f18faa
Distance marks as link between 1D and 2D.
Tom Gottfried <tom@intevation.de>
parents:
77
diff
changeset
|
153 -- distance marks along waterway axis (see SUC7). |
81
acaa485c0c1e
Use different schemas for different diagrams. Add TODOs.
Tom Gottfried <tom@intevation.de>
parents:
80
diff
changeset
|
154 CREATE TABLE wamos_waterway.distance_marks ( |
74 | 155 location_code isrs PRIMARY KEY, |
80 | 156 geom geometry(POINT, 4326), |
78
012948f18faa
Distance marks as link between 1D and 2D.
Tom Gottfried <tom@intevation.de>
parents:
77
diff
changeset
|
157 distance_mark_function varchar(8) REFERENCES distance_mark_functions, |
74 | 158 -- TODO: add relations to stuff provided as enumerations |
159 dummy_attrib varchar, | |
160 "..." varchar | |
75
ed7a50cfbc19
Add sections and stretches stub and fix comment.
Tom Gottfried <tom@intevation.de>
parents:
74
diff
changeset
|
161 -- TODO: add real distance mark attributes (DRC 2.1.7) |
ed7a50cfbc19
Add sections and stretches stub and fix comment.
Tom Gottfried <tom@intevation.de>
parents:
74
diff
changeset
|
162 ); |
ed7a50cfbc19
Add sections and stretches stub and fix comment.
Tom Gottfried <tom@intevation.de>
parents:
74
diff
changeset
|
163 |
81
acaa485c0c1e
Use different schemas for different diagrams. Add TODOs.
Tom Gottfried <tom@intevation.de>
parents:
80
diff
changeset
|
164 CREATE TABLE wamos_waterway.sections_stretches ( |
75
ed7a50cfbc19
Add sections and stretches stub and fix comment.
Tom Gottfried <tom@intevation.de>
parents:
74
diff
changeset
|
165 id varchar PRIMARY KEY, |
ed7a50cfbc19
Add sections and stretches stub and fix comment.
Tom Gottfried <tom@intevation.de>
parents:
74
diff
changeset
|
166 is_section boolean NOT NULL, -- maps 'function' from interface |
ed7a50cfbc19
Add sections and stretches stub and fix comment.
Tom Gottfried <tom@intevation.de>
parents:
74
diff
changeset
|
167 stretch isrsrange, |
ed7a50cfbc19
Add sections and stretches stub and fix comment.
Tom Gottfried <tom@intevation.de>
parents:
74
diff
changeset
|
168 dummy_attrib varchar, |
ed7a50cfbc19
Add sections and stretches stub and fix comment.
Tom Gottfried <tom@intevation.de>
parents:
74
diff
changeset
|
169 "..." varchar |
ed7a50cfbc19
Add sections and stretches stub and fix comment.
Tom Gottfried <tom@intevation.de>
parents:
74
diff
changeset
|
170 -- TODO: add real section/stretch attributes (DRC 2.2.1) |
74 | 171 ); |
172 | |
81
acaa485c0c1e
Use different schemas for different diagrams. Add TODOs.
Tom Gottfried <tom@intevation.de>
parents:
80
diff
changeset
|
173 CREATE TABLE wamos_waterway.waterway_profiles ( |
79
c22ddffc2071
Add waterway profiles stub.
Tom Gottfried <tom@intevation.de>
parents:
78
diff
changeset
|
174 dummy_attrib varchar, |
c22ddffc2071
Add waterway profiles stub.
Tom Gottfried <tom@intevation.de>
parents:
78
diff
changeset
|
175 "..." varchar |
c22ddffc2071
Add waterway profiles stub.
Tom Gottfried <tom@intevation.de>
parents:
78
diff
changeset
|
176 -- TODO: add real profile attributes (DRC 2.2.3) |
c22ddffc2071
Add waterway profiles stub.
Tom Gottfried <tom@intevation.de>
parents:
78
diff
changeset
|
177 ); |
c22ddffc2071
Add waterway profiles stub.
Tom Gottfried <tom@intevation.de>
parents:
78
diff
changeset
|
178 |
56
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
179 -- |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
180 -- Bottlenecks |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
181 -- |
81
acaa485c0c1e
Use different schemas for different diagrams. Add TODOs.
Tom Gottfried <tom@intevation.de>
parents:
80
diff
changeset
|
182 CREATE TABLE wamos_fairway.riverbed_materials ( |
35
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
183 material varchar PRIMARY KEY |
39
830287983657
Comment: details to clarify riverbed material.
Tom Gottfried <tom@intevation.de>
parents:
38
diff
changeset
|
184 -- XXX: Should this table contain choices from DRC 2.2.3 or |
830287983657
Comment: details to clarify riverbed material.
Tom Gottfried <tom@intevation.de>
parents:
38
diff
changeset
|
185 -- from IENC Encoding Guide M.4.3, attribute NATSUR? |
35
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
186 ); |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
187 |
81
acaa485c0c1e
Use different schemas for different diagrams. Add TODOs.
Tom Gottfried <tom@intevation.de>
parents:
80
diff
changeset
|
188 CREATE TABLE wamos_fairway.survey_types ( |
35
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
189 survey_type varchar PRIMARY KEY |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
190 ); |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
191 |
81
acaa485c0c1e
Use different schemas for different diagrams. Add TODOs.
Tom Gottfried <tom@intevation.de>
parents:
80
diff
changeset
|
192 CREATE TABLE wamos_fairway.coverage_types ( |
35
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
193 coverage_type varchar PRIMARY KEY |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
194 ); |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
195 |
81
acaa485c0c1e
Use different schemas for different diagrams. Add TODOs.
Tom Gottfried <tom@intevation.de>
parents:
80
diff
changeset
|
196 CREATE TABLE wamos_fairway.limiting_factors ( |
35
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
197 limiting_factor varchar PRIMARY KEY |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
198 ); |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
199 |
81
acaa485c0c1e
Use different schemas for different diagrams. Add TODOs.
Tom Gottfried <tom@intevation.de>
parents:
80
diff
changeset
|
200 CREATE TABLE wamos_fairway.depth_references ( |
40
535e57373a93
Fix and comments on depth references.
Tom Gottfried <tom@intevation.de>
parents:
39
diff
changeset
|
201 depth_reference varchar(4) PRIMARY KEY |
535e57373a93
Fix and comments on depth references.
Tom Gottfried <tom@intevation.de>
parents:
39
diff
changeset
|
202 -- See col. AB and AI RIS-Index Encoding Guide |
535e57373a93
Fix and comments on depth references.
Tom Gottfried <tom@intevation.de>
parents:
39
diff
changeset
|
203 -- XXX: We need a way to distinguish between geodetic (eg. col. AP |
535e57373a93
Fix and comments on depth references.
Tom Gottfried <tom@intevation.de>
parents:
39
diff
changeset
|
204 -- RIS-Index) and other references (e.g. col. AB and AI): |
535e57373a93
Fix and comments on depth references.
Tom Gottfried <tom@intevation.de>
parents:
39
diff
changeset
|
205 -- _ multi-column FK with a boolean column (geodetic/non-geodetic; |
535e57373a93
Fix and comments on depth references.
Tom Gottfried <tom@intevation.de>
parents:
39
diff
changeset
|
206 -- i.e. absolut/not absolut) and DEFAULTs and CHECKs at the FK side. |
535e57373a93
Fix and comments on depth references.
Tom Gottfried <tom@intevation.de>
parents:
39
diff
changeset
|
207 -- _ Do not mixup things with different meanings in one table at all |
535e57373a93
Fix and comments on depth references.
Tom Gottfried <tom@intevation.de>
parents:
39
diff
changeset
|
208 -- (which would mean a model differing a bit from RIS-Index ideas) |
35
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
209 ); |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
210 |
55
ecb9bb0591c9
Note on spurious nullability.
Tom Gottfried <tom@intevation.de>
parents:
54
diff
changeset
|
211 -- XXX: Nullability differs between DRC (attributes marked "O") and WSDL |
ecb9bb0591c9
Note on spurious nullability.
Tom Gottfried <tom@intevation.de>
parents:
54
diff
changeset
|
212 -- (minOccurs=0; nillable seems to be set arbitrarily as even bottleneck_id and |
ecb9bb0591c9
Note on spurious nullability.
Tom Gottfried <tom@intevation.de>
parents:
54
diff
changeset
|
213 -- fk_g_fid (both mandatory, i.e. marked "M" in DRC) have nillable="true" in WSDL) |
81
acaa485c0c1e
Use different schemas for different diagrams. Add TODOs.
Tom Gottfried <tom@intevation.de>
parents:
80
diff
changeset
|
214 CREATE TABLE wamos_fairway.bottlenecks ( |
35
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
215 bottleneck_id varchar PRIMARY KEY, |
54
285146e8c9c5
Align constraints with WSDL (NOT NULL vs. minOccurs).
Tom Gottfried <tom@intevation.de>
parents:
53
diff
changeset
|
216 fk_g_fid isrs NOT NULL REFERENCES gauges, |
35
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
217 -- XXX: DRC references "ch. 3.1.1", which does not exist in document. |
54
285146e8c9c5
Align constraints with WSDL (NOT NULL vs. minOccurs).
Tom Gottfried <tom@intevation.de>
parents:
53
diff
changeset
|
218 objnam varchar, |
285146e8c9c5
Align constraints with WSDL (NOT NULL vs. minOccurs).
Tom Gottfried <tom@intevation.de>
parents:
53
diff
changeset
|
219 nobjnm varchar, |
35
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
220 stretch isrsrange NOT NULL, |
80 | 221 area geometry(POLYGON, 4326) NOT NULL, |
42 | 222 rb char(2) NOT NULL REFERENCES countries, -- from rb_lb in interface |
223 lb char(2) NOT NULL REFERENCES countries, -- from rb_lb in interface | |
41
dd858a74b4e9
Set columns referencing countries next to each other.
Tom Gottfried <tom@intevation.de>
parents:
40
diff
changeset
|
224 responsible_country char(2) NOT NULL REFERENCES countries, |
35
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
225 revisiting_time smallint NOT NULL, |
46 | 226 limiting varchar NOT NULL REFERENCES limiting_factors, |
35
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
227 surtyp varchar NOT NULL REFERENCES survey_types, |
45
cb25ddf16cbf
Probably attributes of sounding results
Tom Gottfried <tom@intevation.de>
parents:
44
diff
changeset
|
228 -- XXX: Also an attribut of sounding result? |
54
285146e8c9c5
Align constraints with WSDL (NOT NULL vs. minOccurs).
Tom Gottfried <tom@intevation.de>
parents:
53
diff
changeset
|
229 coverage varchar REFERENCES coverage_types, |
45
cb25ddf16cbf
Probably attributes of sounding results
Tom Gottfried <tom@intevation.de>
parents:
44
diff
changeset
|
230 -- XXX: Also an attribut of sounding result? |
35
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
231 -- CHECK allowed combinations of surtyp and coverage or |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
232 -- different model approach? |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
233 depth_reference char(3) NOT NULL REFERENCES depth_references, |
45
cb25ddf16cbf
Probably attributes of sounding results
Tom Gottfried <tom@intevation.de>
parents:
44
diff
changeset
|
234 -- XXX: Also an attribut of sounding result? |
59
37faa7359ea6
Interfaces may provide timestamps with time zone.
Tom Gottfried <tom@intevation.de>
parents:
58
diff
changeset
|
235 date_info timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, |
60
f0ca64da9446
Add attribute to mark data sets as checked in staging area.
Tom Gottfried <tom@intevation.de>
parents:
59
diff
changeset
|
236 source_organization varchar NOT NULL, |
47
a03ff9076969
Delivered by interface for other uses than WAMOS.
Tom Gottfried <tom@intevation.de>
parents:
46
diff
changeset
|
237 -- additional_data xml -- Currently not relevant for WAMOS |
60
f0ca64da9446
Add attribute to mark data sets as checked in staging area.
Tom Gottfried <tom@intevation.de>
parents:
59
diff
changeset
|
238 staging_done boolean NOT NULL DEFAULT false |
35
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
239 ); |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
240 CREATE TRIGGER bottleneck_date_info BEFORE UPDATE ON bottlenecks |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
241 FOR EACH ROW EXECUTE PROCEDURE update_date_info(); |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
242 |
81
acaa485c0c1e
Use different schemas for different diagrams. Add TODOs.
Tom Gottfried <tom@intevation.de>
parents:
80
diff
changeset
|
243 CREATE TABLE wamos_fairway.bottlenecks_riverbed_materials ( |
44
dcc3b1134b24
Multiple riverbed materials per bottleneck possible.
Tom Gottfried <tom@intevation.de>
parents:
43
diff
changeset
|
244 bottleneck_id varchar REFERENCES bottlenecks, |
dcc3b1134b24
Multiple riverbed materials per bottleneck possible.
Tom Gottfried <tom@intevation.de>
parents:
43
diff
changeset
|
245 riverbed varchar REFERENCES riverbed_materials, |
dcc3b1134b24
Multiple riverbed materials per bottleneck possible.
Tom Gottfried <tom@intevation.de>
parents:
43
diff
changeset
|
246 -- XXX: should be 'natsur' according to IENC Encoding Guide M.4.3 |
dcc3b1134b24
Multiple riverbed materials per bottleneck possible.
Tom Gottfried <tom@intevation.de>
parents:
43
diff
changeset
|
247 PRIMARY KEY (bottleneck_id, riverbed) |
dcc3b1134b24
Multiple riverbed materials per bottleneck possible.
Tom Gottfried <tom@intevation.de>
parents:
43
diff
changeset
|
248 ); |
dcc3b1134b24
Multiple riverbed materials per bottleneck possible.
Tom Gottfried <tom@intevation.de>
parents:
43
diff
changeset
|
249 |
81
acaa485c0c1e
Use different schemas for different diagrams. Add TODOs.
Tom Gottfried <tom@intevation.de>
parents:
80
diff
changeset
|
250 CREATE TABLE wamos_fairway.sounding_results ( |
35
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
251 bottleneck_id varchar NOT NULL REFERENCES bottlenecks, |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
252 date_info date NOT NULL, |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
253 PRIMARY KEY (bottleneck_id, date_info), |
80 | 254 area geometry(POLYGON, 4326) NOT NULL, |
45
cb25ddf16cbf
Probably attributes of sounding results
Tom Gottfried <tom@intevation.de>
parents:
44
diff
changeset
|
255 surtyp varchar NOT NULL REFERENCES survey_types, |
54
285146e8c9c5
Align constraints with WSDL (NOT NULL vs. minOccurs).
Tom Gottfried <tom@intevation.de>
parents:
53
diff
changeset
|
256 coverage varchar REFERENCES coverage_types, |
45
cb25ddf16cbf
Probably attributes of sounding results
Tom Gottfried <tom@intevation.de>
parents:
44
diff
changeset
|
257 depth_reference char(3) NOT NULL REFERENCES depth_references, |
60
f0ca64da9446
Add attribute to mark data sets as checked in staging area.
Tom Gottfried <tom@intevation.de>
parents:
59
diff
changeset
|
258 sounding_data raster NOT NULL, |
f0ca64da9446
Add attribute to mark data sets as checked in staging area.
Tom Gottfried <tom@intevation.de>
parents:
59
diff
changeset
|
259 staging_done boolean NOT NULL DEFAULT false |
35
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
260 ); |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
261 |
56
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
262 -- |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
263 -- Fairway availability |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
264 -- |
81
acaa485c0c1e
Use different schemas for different diagrams. Add TODOs.
Tom Gottfried <tom@intevation.de>
parents:
80
diff
changeset
|
265 CREATE TABLE wamos_fairway.spot_marks ( |
56
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
266 mark_name varchar PRIMARY KEY |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
267 -- Use smallint because of fairway availability provided on daily basis? |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
268 ); |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
269 |
81
acaa485c0c1e
Use different schemas for different diagrams. Add TODOs.
Tom Gottfried <tom@intevation.de>
parents:
80
diff
changeset
|
270 CREATE TABLE wamos_fairway.levels_of_service ( |
56
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
271 level_of_service smallint PRIMARY KEY |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
272 ); |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
273 |
81
acaa485c0c1e
Use different schemas for different diagrams. Add TODOs.
Tom Gottfried <tom@intevation.de>
parents:
80
diff
changeset
|
274 CREATE TABLE wamos_fairway.measure_types ( |
58
30cb2f87c268
Add effective fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
56
diff
changeset
|
275 measure_type varchar PRIMARY KEY |
30cb2f87c268
Add effective fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
56
diff
changeset
|
276 ); |
30cb2f87c268
Add effective fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
56
diff
changeset
|
277 |
81
acaa485c0c1e
Use different schemas for different diagrams. Add TODOs.
Tom Gottfried <tom@intevation.de>
parents:
80
diff
changeset
|
278 CREATE TABLE wamos_fairway.fairway_dimensions ( |
76
2a6e49a7b839
Add fairway dimensions stub.
Tom Gottfried <tom@intevation.de>
parents:
75
diff
changeset
|
279 level_of_service smallint REFERENCES levels_of_service, |
2a6e49a7b839
Add fairway dimensions stub.
Tom Gottfried <tom@intevation.de>
parents:
75
diff
changeset
|
280 dummy_attrib varchar, |
2a6e49a7b839
Add fairway dimensions stub.
Tom Gottfried <tom@intevation.de>
parents:
75
diff
changeset
|
281 "..." varchar |
2a6e49a7b839
Add fairway dimensions stub.
Tom Gottfried <tom@intevation.de>
parents:
75
diff
changeset
|
282 -- TODO: add real fairway dimension attributes (DRC 2.2.2) |
2a6e49a7b839
Add fairway dimensions stub.
Tom Gottfried <tom@intevation.de>
parents:
75
diff
changeset
|
283 ); |
2a6e49a7b839
Add fairway dimensions stub.
Tom Gottfried <tom@intevation.de>
parents:
75
diff
changeset
|
284 |
81
acaa485c0c1e
Use different schemas for different diagrams. Add TODOs.
Tom Gottfried <tom@intevation.de>
parents:
80
diff
changeset
|
285 CREATE TABLE wamos_fairway.fairway_availability ( |
66
21df0e95db4a
Fix thinkos and syntax errors in previous commit.
Tom Gottfried <tom@intevation.de>
parents:
65
diff
changeset
|
286 id int PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, |
67 | 287 position varchar REFERENCES spot_marks, |
56
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
288 bottleneck_id varchar NOT NULL REFERENCES bottlenecks, |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
289 surdat date NOT NULL, |
66
21df0e95db4a
Fix thinkos and syntax errors in previous commit.
Tom Gottfried <tom@intevation.de>
parents:
65
diff
changeset
|
290 UNIQUE (bottleneck_id, surdat), |
56
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
291 -- additional_data xml -- Currently not relevant for WAMOS |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
292 critical boolean, |
59
37faa7359ea6
Interfaces may provide timestamps with time zone.
Tom Gottfried <tom@intevation.de>
parents:
58
diff
changeset
|
293 date_info timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, |
56
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
294 source_organization varchar NOT NULL |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
295 ); |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
296 CREATE TRIGGER fairway_availability_date_info |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
297 BEFORE UPDATE ON fairway_availability |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
298 FOR EACH ROW EXECUTE PROCEDURE update_date_info(); |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
299 |
81
acaa485c0c1e
Use different schemas for different diagrams. Add TODOs.
Tom Gottfried <tom@intevation.de>
parents:
80
diff
changeset
|
300 CREATE TABLE wamos_fairway.fa_reference_values ( |
66
21df0e95db4a
Fix thinkos and syntax errors in previous commit.
Tom Gottfried <tom@intevation.de>
parents:
65
diff
changeset
|
301 fairway_availability_id int NOT NULL REFERENCES fairway_availability, |
56
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
302 level_of_service smallint NOT NULL REFERENCES levels_of_service, |
65
cad19acc53b3
Avoid duplicate direct relations in composite primary keys.
Tom Gottfried <tom@intevation.de>
parents:
64
diff
changeset
|
303 PRIMARY KEY (fairway_availability_id, level_of_service), |
56
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
304 fairway_depth smallint, |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
305 fairway_width smallint, |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
306 fairway_radius int, |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
307 CHECK(COALESCE(fairway_depth, fairway_width, fairway_radius) IS NOT NULL), |
80 | 308 shallowest_spot geometry(POINT, 4326) |
56
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
309 ); |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
310 |
81
acaa485c0c1e
Use different schemas for different diagrams. Add TODOs.
Tom Gottfried <tom@intevation.de>
parents:
80
diff
changeset
|
311 CREATE TABLE wamos_fairway.bottleneck_pdfs ( |
66
21df0e95db4a
Fix thinkos and syntax errors in previous commit.
Tom Gottfried <tom@intevation.de>
parents:
65
diff
changeset
|
312 fairway_availability_id int NOT NULL REFERENCES fairway_availability, |
56
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
313 profile_pdf_filename varchar NOT NULL, -- redundant to last part of URL |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
314 profile_pdf_url varchar NOT NULL, -- prohibit insecure URLs somehow? |
65
cad19acc53b3
Avoid duplicate direct relations in composite primary keys.
Tom Gottfried <tom@intevation.de>
parents:
64
diff
changeset
|
315 PRIMARY KEY (fairway_availability_id, profile_pdf_url), |
59
37faa7359ea6
Interfaces may provide timestamps with time zone.
Tom Gottfried <tom@intevation.de>
parents:
58
diff
changeset
|
316 pdf_generation_date timestamp with time zone NOT NULL, |
56
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
317 source_organization varchar NOT NULL |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
318 ); |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
319 |
81
acaa485c0c1e
Use different schemas for different diagrams. Add TODOs.
Tom Gottfried <tom@intevation.de>
parents:
80
diff
changeset
|
320 CREATE TABLE wamos_fairway.effective_fairway_availability ( |
66
21df0e95db4a
Fix thinkos and syntax errors in previous commit.
Tom Gottfried <tom@intevation.de>
parents:
65
diff
changeset
|
321 fairway_availability_id int NOT NULL REFERENCES fairway_availability, |
59
37faa7359ea6
Interfaces may provide timestamps with time zone.
Tom Gottfried <tom@intevation.de>
parents:
58
diff
changeset
|
322 measure_date timestamp with time zone NOT NULL, |
58
30cb2f87c268
Add effective fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
56
diff
changeset
|
323 level_of_service smallint NOT NULL REFERENCES levels_of_service, |
65
cad19acc53b3
Avoid duplicate direct relations in composite primary keys.
Tom Gottfried <tom@intevation.de>
parents:
64
diff
changeset
|
324 PRIMARY KEY (fairway_availability_id, measure_date, level_of_service), |
58
30cb2f87c268
Add effective fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
56
diff
changeset
|
325 available_depth_value smallint, |
30cb2f87c268
Add effective fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
56
diff
changeset
|
326 available_width_value smallint, |
30cb2f87c268
Add effective fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
56
diff
changeset
|
327 water_level_value smallint, |
30cb2f87c268
Add effective fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
56
diff
changeset
|
328 CHECK(COALESCE(available_depth_value, available_width_value, |
30cb2f87c268
Add effective fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
56
diff
changeset
|
329 water_level_value) IS NOT NULL), |
30cb2f87c268
Add effective fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
56
diff
changeset
|
330 measure_type varchar NOT NULL REFERENCES measure_types, |
30cb2f87c268
Add effective fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
56
diff
changeset
|
331 source_organization varchar NOT NULL, |
59
37faa7359ea6
Interfaces may provide timestamps with time zone.
Tom Gottfried <tom@intevation.de>
parents:
58
diff
changeset
|
332 forecast_generation_time timestamp with time zone, |
58
30cb2f87c268
Add effective fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
56
diff
changeset
|
333 CHECK(measure_type <> 'forecasted' |
30cb2f87c268
Add effective fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
56
diff
changeset
|
334 OR forecast_generation_time IS NOT NULL), |
59
37faa7359ea6
Interfaces may provide timestamps with time zone.
Tom Gottfried <tom@intevation.de>
parents:
58
diff
changeset
|
335 value_lifetime timestamp with time zone, |
58
30cb2f87c268
Add effective fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
56
diff
changeset
|
336 CHECK(measure_type = 'minimum guaranteed' OR value_lifetime IS NOT NULL) |
56
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
337 ); |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
338 |
35
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
339 COMMIT; |