Mercurial > gemma
annotate wamos.sql @ 60:f0ca64da9446
Add attribute to mark data sets as checked in staging area.
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Fri, 25 May 2018 15:42:57 +0200 |
parents | 37faa7359ea6 |
children | 39e0e3d8dd1b |
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 |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
3 CREATE EXTENSION postgis; |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
4 |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
5 CREATE FUNCTION update_date_info() RETURNS trigger |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
6 LANGUAGE plpgsql |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
7 AS $$ |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
8 BEGIN |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
9 NEW.date_info = CURRENT_TIMESTAMP; |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
10 RETURN NEW; |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
11 END; |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
12 $$; |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
13 |
37
6f273a649f08
Be more specific with ISRS and update some comments.
Tom Gottfried <tom@intevation.de>
parents:
35
diff
changeset
|
14 -- 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
|
15 -- See RIS-Index Encoding Guide |
35
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
16 CREATE TYPE isrs AS ( |
37
6f273a649f08
Be more specific with ISRS and update some comments.
Tom Gottfried <tom@intevation.de>
parents:
35
diff
changeset
|
17 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
|
18 -- 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
|
19 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
|
20 -- 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
|
21 fairway_section char(5), |
6f273a649f08
Be more specific with ISRS and update some comments.
Tom Gottfried <tom@intevation.de>
parents:
35
diff
changeset
|
22 object_reference char(5), |
6f273a649f08
Be more specific with ISRS and update some comments.
Tom Gottfried <tom@intevation.de>
parents:
35
diff
changeset
|
23 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
|
24 ); |
35
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
25 |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
26 CREATE TYPE isrsrange AS RANGE ( |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
27 subtype = isrs |
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 |
53 | 30 -- Eventually obsolete. |
31 -- See https://roundup-intern.intevation.de/wamos/issue5 | |
35
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
32 CREATE TABLE rwdrs ( |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
33 stretch isrsrange PRIMARY KEY, |
37
6f273a649f08
Be more specific with ISRS and update some comments.
Tom Gottfried <tom@intevation.de>
parents:
35
diff
changeset
|
34 -- https://www.postgresql.org/docs/10/static/sql-createindex.html: |
6f273a649f08
Be more specific with ISRS and update some comments.
Tom Gottfried <tom@intevation.de>
parents:
35
diff
changeset
|
35 -- Only B-tree supports UNIQUE indexes, but we need the GIST index |
6f273a649f08
Be more specific with ISRS and update some comments.
Tom Gottfried <tom@intevation.de>
parents:
35
diff
changeset
|
36 -- below anyhow. |
35
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
37 -- Is it a good idea to build B-tree indexes on relatively large |
37
6f273a649f08
Be more specific with ISRS and update some comments.
Tom Gottfried <tom@intevation.de>
parents:
35
diff
changeset
|
38 -- composites of string values or should we use inter PKs? |
6f273a649f08
Be more specific with ISRS and update some comments.
Tom Gottfried <tom@intevation.de>
parents:
35
diff
changeset
|
39 -- => In case the index is used and cache space becomes a limiting |
6f273a649f08
Be more specific with ISRS and update some comments.
Tom Gottfried <tom@intevation.de>
parents:
35
diff
changeset
|
40 -- factor, this might be an issue. |
35
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
41 rwdr double precision NOT NULL, |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
42 EXCLUDE USING GIST (stretch WITH &&) |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
43 ); |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
44 |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
45 CREATE TABLE gauges ( |
38
529319bc3c5b
Mark gauges table as placeholder.
Tom Gottfried <tom@intevation.de>
parents:
37
diff
changeset
|
46 location isrs PRIMARY KEY, |
43 | 47 dummy_attrib varchar, |
48 "..." varchar | |
38
529319bc3c5b
Mark gauges table as placeholder.
Tom Gottfried <tom@intevation.de>
parents:
37
diff
changeset
|
49 -- 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
|
50 ); |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
51 |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
52 CREATE TABLE countries ( |
37
6f273a649f08
Be more specific with ISRS and update some comments.
Tom Gottfried <tom@intevation.de>
parents:
35
diff
changeset
|
53 country_code char(2) PRIMARY KEY -- ISO 3166 country code |
6f273a649f08
Be more specific with ISRS and update some comments.
Tom Gottfried <tom@intevation.de>
parents:
35
diff
changeset
|
54 -- A smallint PK would require even less disk space i.e. on the FK side. |
6f273a649f08
Be more specific with ISRS and update some comments.
Tom Gottfried <tom@intevation.de>
parents:
35
diff
changeset
|
55 -- This might be an issue in case cache space becomes a limiting |
6f273a649f08
Be more specific with ISRS and update some comments.
Tom Gottfried <tom@intevation.de>
parents:
35
diff
changeset
|
56 -- factor when there are many FKs pointing here. |
35
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
57 ); |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
58 |
56
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
59 -- |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
60 -- Bottlenecks |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
61 -- |
35
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
62 CREATE TABLE riverbed_materials ( |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
63 material varchar PRIMARY KEY |
39
830287983657
Comment: details to clarify riverbed material.
Tom Gottfried <tom@intevation.de>
parents:
38
diff
changeset
|
64 -- 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
|
65 -- 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
|
66 ); |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
67 |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
68 CREATE TABLE survey_types ( |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
69 survey_type varchar PRIMARY KEY |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
70 ); |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
71 |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
72 CREATE TABLE coverage_types ( |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
73 coverage_type varchar PRIMARY KEY |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
74 ); |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
75 |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
76 CREATE TABLE limiting_factors ( |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
77 limiting_factor varchar PRIMARY KEY |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
78 ); |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
79 |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
80 CREATE TABLE depth_references ( |
40
535e57373a93
Fix and comments on depth references.
Tom Gottfried <tom@intevation.de>
parents:
39
diff
changeset
|
81 depth_reference varchar(4) PRIMARY KEY |
535e57373a93
Fix and comments on depth references.
Tom Gottfried <tom@intevation.de>
parents:
39
diff
changeset
|
82 -- 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
|
83 -- 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
|
84 -- 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
|
85 -- _ 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
|
86 -- 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
|
87 -- _ 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
|
88 -- (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
|
89 ); |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
90 |
55
ecb9bb0591c9
Note on spurious nullability.
Tom Gottfried <tom@intevation.de>
parents:
54
diff
changeset
|
91 -- XXX: Nullability differs between DRC (attributes marked "O") and WSDL |
ecb9bb0591c9
Note on spurious nullability.
Tom Gottfried <tom@intevation.de>
parents:
54
diff
changeset
|
92 -- (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
|
93 -- fk_g_fid (both mandatory, i.e. marked "M" in DRC) have nillable="true" in WSDL) |
35
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
94 CREATE TABLE bottlenecks ( |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
95 bottleneck_id varchar PRIMARY KEY, |
54
285146e8c9c5
Align constraints with WSDL (NOT NULL vs. minOccurs).
Tom Gottfried <tom@intevation.de>
parents:
53
diff
changeset
|
96 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
|
97 -- 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
|
98 objnam varchar, |
285146e8c9c5
Align constraints with WSDL (NOT NULL vs. minOccurs).
Tom Gottfried <tom@intevation.de>
parents:
53
diff
changeset
|
99 nobjnm varchar, |
35
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
100 stretch isrsrange NOT NULL, |
50
a7cb0c2c3dd7
An area will be processed on upload for bottlenecks (see SUC8).
Tom Gottfried <tom@intevation.de>
parents:
49
diff
changeset
|
101 area geometry(POLYGON, 3146) NOT NULL, |
42 | 102 rb char(2) NOT NULL REFERENCES countries, -- from rb_lb in interface |
103 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
|
104 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
|
105 revisiting_time smallint NOT NULL, |
46 | 106 limiting varchar NOT NULL REFERENCES limiting_factors, |
35
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
107 surtyp varchar NOT NULL REFERENCES survey_types, |
45
cb25ddf16cbf
Probably attributes of sounding results
Tom Gottfried <tom@intevation.de>
parents:
44
diff
changeset
|
108 -- 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
|
109 coverage varchar REFERENCES coverage_types, |
45
cb25ddf16cbf
Probably attributes of sounding results
Tom Gottfried <tom@intevation.de>
parents:
44
diff
changeset
|
110 -- XXX: Also an attribut of sounding result? |
35
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
111 -- CHECK allowed combinations of surtyp and coverage or |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
112 -- different model approach? |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
113 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
|
114 -- 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
|
115 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
|
116 source_organization varchar NOT NULL, |
47
a03ff9076969
Delivered by interface for other uses than WAMOS.
Tom Gottfried <tom@intevation.de>
parents:
46
diff
changeset
|
117 -- 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
|
118 staging_done boolean NOT NULL DEFAULT false |
35
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
119 ); |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
120 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
|
121 FOR EACH ROW EXECUTE PROCEDURE update_date_info(); |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
122 |
44
dcc3b1134b24
Multiple riverbed materials per bottleneck possible.
Tom Gottfried <tom@intevation.de>
parents:
43
diff
changeset
|
123 CREATE TABLE bottlenecks_riverbed_materials ( |
dcc3b1134b24
Multiple riverbed materials per bottleneck possible.
Tom Gottfried <tom@intevation.de>
parents:
43
diff
changeset
|
124 bottleneck_id varchar REFERENCES bottlenecks, |
dcc3b1134b24
Multiple riverbed materials per bottleneck possible.
Tom Gottfried <tom@intevation.de>
parents:
43
diff
changeset
|
125 riverbed varchar REFERENCES riverbed_materials, |
dcc3b1134b24
Multiple riverbed materials per bottleneck possible.
Tom Gottfried <tom@intevation.de>
parents:
43
diff
changeset
|
126 -- 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
|
127 PRIMARY KEY (bottleneck_id, riverbed) |
dcc3b1134b24
Multiple riverbed materials per bottleneck possible.
Tom Gottfried <tom@intevation.de>
parents:
43
diff
changeset
|
128 ); |
dcc3b1134b24
Multiple riverbed materials per bottleneck possible.
Tom Gottfried <tom@intevation.de>
parents:
43
diff
changeset
|
129 |
35
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
130 CREATE TABLE sounding_results ( |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
131 bottleneck_id varchar NOT NULL REFERENCES bottlenecks, |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
132 date_info date NOT NULL, |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
133 PRIMARY KEY (bottleneck_id, date_info), |
51
bb81404e8ad1
An area will be processed or given for clipping for surveys (see SUC10).
Tom Gottfried <tom@intevation.de>
parents:
50
diff
changeset
|
134 area geometry(POLYGON, 3146) NOT NULL, |
45
cb25ddf16cbf
Probably attributes of sounding results
Tom Gottfried <tom@intevation.de>
parents:
44
diff
changeset
|
135 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
|
136 coverage varchar REFERENCES coverage_types, |
45
cb25ddf16cbf
Probably attributes of sounding results
Tom Gottfried <tom@intevation.de>
parents:
44
diff
changeset
|
137 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
|
138 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
|
139 staging_done boolean NOT NULL DEFAULT false |
35
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
140 ); |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
141 |
56
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
142 -- |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
143 -- Fairway availability |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
144 -- |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
145 CREATE TABLE spot_marks ( |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
146 mark_name varchar PRIMARY KEY |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
147 -- 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
|
148 ); |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
149 |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
150 CREATE TABLE levels_of_service ( |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
151 level_of_service smallint PRIMARY KEY |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
152 ); |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
153 |
58
30cb2f87c268
Add effective fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
56
diff
changeset
|
154 CREATE TABLE measure_types ( |
30cb2f87c268
Add effective fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
56
diff
changeset
|
155 measure_type varchar PRIMARY KEY |
30cb2f87c268
Add effective fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
56
diff
changeset
|
156 ); |
30cb2f87c268
Add effective fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
56
diff
changeset
|
157 |
56
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
158 CREATE TABLE fairway_availability ( |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
159 bottleneck_id varchar NOT NULL REFERENCES bottlenecks, |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
160 surdat date NOT NULL, |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
161 PRIMARY KEY (bottleneck_id, surdat), |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
162 position varchar REFERENCES spot_marks, |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
163 -- 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
|
164 critical boolean, |
59
37faa7359ea6
Interfaces may provide timestamps with time zone.
Tom Gottfried <tom@intevation.de>
parents:
58
diff
changeset
|
165 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
|
166 source_organization varchar NOT NULL |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
167 ); |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
168 CREATE TRIGGER fairway_availability_date_info |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
169 BEFORE UPDATE ON fairway_availability |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
170 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
|
171 |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
172 CREATE TABLE fa_reference_values ( |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
173 bottleneck_id varchar NOT NULL REFERENCES bottlenecks, |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
174 surdat date NOT NULL, |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
175 FOREIGN KEY (bottleneck_id, surdat) REFERENCES fairway_availability, |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
176 level_of_service smallint NOT NULL REFERENCES levels_of_service, |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
177 PRIMARY KEY (bottleneck_id, surdat, level_of_service), |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
178 fairway_depth smallint, |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
179 fairway_width smallint, |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
180 fairway_radius int, |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
181 CHECK(COALESCE(fairway_depth, fairway_width, fairway_radius) IS NOT NULL), |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
182 shallowest_spot geometry(POINT, 3146) |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
183 ); |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
184 |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
185 CREATE TABLE bottleneck_pdfs ( |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
186 bottleneck_id varchar NOT NULL REFERENCES bottlenecks, |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
187 surdat date NOT NULL, |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
188 FOREIGN KEY (bottleneck_id, surdat) REFERENCES fairway_availability, |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
189 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
|
190 profile_pdf_url varchar NOT NULL, -- prohibit insecure URLs somehow? |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
191 PRIMARY KEY (bottleneck_id, surdat, profile_pdf_url), |
59
37faa7359ea6
Interfaces may provide timestamps with time zone.
Tom Gottfried <tom@intevation.de>
parents:
58
diff
changeset
|
192 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
|
193 source_organization varchar NOT NULL |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
194 ); |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
195 |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
196 CREATE TABLE effective_fairway_availability ( |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
197 bottleneck_id varchar NOT NULL REFERENCES bottlenecks, |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
198 surdat date NOT NULL, |
58
30cb2f87c268
Add effective fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
56
diff
changeset
|
199 FOREIGN KEY (bottleneck_id, surdat) REFERENCES fairway_availability, |
59
37faa7359ea6
Interfaces may provide timestamps with time zone.
Tom Gottfried <tom@intevation.de>
parents:
58
diff
changeset
|
200 measure_date timestamp with time zone NOT NULL, |
58
30cb2f87c268
Add effective fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
56
diff
changeset
|
201 level_of_service smallint NOT NULL REFERENCES levels_of_service, |
30cb2f87c268
Add effective fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
56
diff
changeset
|
202 PRIMARY KEY (bottleneck_id, surdat, measure_date, level_of_service), |
30cb2f87c268
Add effective fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
56
diff
changeset
|
203 available_depth_value smallint, |
30cb2f87c268
Add effective fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
56
diff
changeset
|
204 available_width_value smallint, |
30cb2f87c268
Add effective fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
56
diff
changeset
|
205 water_level_value smallint, |
30cb2f87c268
Add effective fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
56
diff
changeset
|
206 CHECK(COALESCE(available_depth_value, available_width_value, |
30cb2f87c268
Add effective fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
56
diff
changeset
|
207 water_level_value) IS NOT NULL), |
30cb2f87c268
Add effective fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
56
diff
changeset
|
208 measure_type varchar NOT NULL REFERENCES measure_types, |
30cb2f87c268
Add effective fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
56
diff
changeset
|
209 source_organization varchar NOT NULL, |
59
37faa7359ea6
Interfaces may provide timestamps with time zone.
Tom Gottfried <tom@intevation.de>
parents:
58
diff
changeset
|
210 forecast_generation_time timestamp with time zone, |
58
30cb2f87c268
Add effective fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
56
diff
changeset
|
211 CHECK(measure_type <> 'forecasted' |
30cb2f87c268
Add effective fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
56
diff
changeset
|
212 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
|
213 value_lifetime timestamp with time zone, |
58
30cb2f87c268
Add effective fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
56
diff
changeset
|
214 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
|
215 ); |
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
216 |
35
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
217 COMMIT; |