Mercurial > gemma
annotate schema/gemma.sql @ 1996:fda5c78fb7d3 importschedulerefac
moved components
author | Thomas Junk <thomas.junk@intevation.de> |
---|---|
date | Thu, 24 Jan 2019 13:43:36 +0100 |
parents | f9f1babe52ae |
children | 48001472e1d8 8eeb0b5eb340 |
rev | line source |
---|---|
1298
6590208e3ee1
add headers for licensing to some schema files
Fadi Abbud <fadi.abbud@intevation.de>
parents:
1288
diff
changeset
|
1 -- This is Free Software under GNU Affero General Public License v >= 3.0 |
6590208e3ee1
add headers for licensing to some schema files
Fadi Abbud <fadi.abbud@intevation.de>
parents:
1288
diff
changeset
|
2 -- without warranty, see README.md and license for details. |
6590208e3ee1
add headers for licensing to some schema files
Fadi Abbud <fadi.abbud@intevation.de>
parents:
1288
diff
changeset
|
3 |
6590208e3ee1
add headers for licensing to some schema files
Fadi Abbud <fadi.abbud@intevation.de>
parents:
1288
diff
changeset
|
4 -- SPDX-License-Identifier: AGPL-3.0-or-later |
6590208e3ee1
add headers for licensing to some schema files
Fadi Abbud <fadi.abbud@intevation.de>
parents:
1288
diff
changeset
|
5 -- License-Filename: LICENSES/AGPL-3.0.txt |
6590208e3ee1
add headers for licensing to some schema files
Fadi Abbud <fadi.abbud@intevation.de>
parents:
1288
diff
changeset
|
6 |
6590208e3ee1
add headers for licensing to some schema files
Fadi Abbud <fadi.abbud@intevation.de>
parents:
1288
diff
changeset
|
7 -- Copyright (C) 2018 by via donau |
6590208e3ee1
add headers for licensing to some schema files
Fadi Abbud <fadi.abbud@intevation.de>
parents:
1288
diff
changeset
|
8 -- – Österreichische Wasserstraßen-Gesellschaft mbH |
6590208e3ee1
add headers for licensing to some schema files
Fadi Abbud <fadi.abbud@intevation.de>
parents:
1288
diff
changeset
|
9 -- Software engineering by Intevation GmbH |
6590208e3ee1
add headers for licensing to some schema files
Fadi Abbud <fadi.abbud@intevation.de>
parents:
1288
diff
changeset
|
10 |
6590208e3ee1
add headers for licensing to some schema files
Fadi Abbud <fadi.abbud@intevation.de>
parents:
1288
diff
changeset
|
11 -- Author(s): |
1301
2304778c4432
add headers for licensing to some schema files
Fadi Abbud <fadi.abbud@intevation.de>
parents:
1298
diff
changeset
|
12 -- * Tom Gottfried <tom@intevation.de> |
1336
f65d1767452c
add headers for licensing to some schema files
Fadi Abbud <fadi.abbud@intevation.de>
parents:
1301
diff
changeset
|
13 -- * Sascha Teichmann <sascha.teichmann@intevation.de> |
1298
6590208e3ee1
add headers for licensing to some schema files
Fadi Abbud <fadi.abbud@intevation.de>
parents:
1288
diff
changeset
|
14 |
35
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
15 BEGIN; |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
16 |
81
acaa485c0c1e
Use different schemas for different diagrams. Add TODOs.
Tom Gottfried <tom@intevation.de>
parents:
80
diff
changeset
|
17 -- |
acaa485c0c1e
Use different schemas for different diagrams. Add TODOs.
Tom Gottfried <tom@intevation.de>
parents:
80
diff
changeset
|
18 -- Infrastructure |
acaa485c0c1e
Use different schemas for different diagrams. Add TODOs.
Tom Gottfried <tom@intevation.de>
parents:
80
diff
changeset
|
19 -- |
35
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
20 CREATE EXTENSION postgis; |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
21 |
96
d036e1bd5f00
Add roles, privileges and RLS policies.
Tom Gottfried <tom@intevation.de>
parents:
95
diff
changeset
|
22 -- TODO: will there ever be UPDATEs or can we drop that function due to |
d036e1bd5f00
Add roles, privileges and RLS policies.
Tom Gottfried <tom@intevation.de>
parents:
95
diff
changeset
|
23 -- historicisation? |
35
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
24 CREATE FUNCTION update_date_info() RETURNS trigger |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
25 LANGUAGE plpgsql |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
26 AS $$ |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
27 BEGIN |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
28 NEW.date_info = CURRENT_TIMESTAMP; |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
29 RETURN NEW; |
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
30 END; |
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 -- |
115
d349db18bece
s/wamos/gemma/g on database schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
113
diff
changeset
|
34 -- GEMMA data |
81
acaa485c0c1e
Use different schemas for different diagrams. Add TODOs.
Tom Gottfried <tom@intevation.de>
parents:
80
diff
changeset
|
35 -- |
195
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
36 |
268
72062ca52746
Make user_profiles table invisible for users
Tom Gottfried <tom@intevation.de>
parents:
234
diff
changeset
|
37 -- Namespace not to be accessed directly by any user |
72062ca52746
Make user_profiles table invisible for users
Tom Gottfried <tom@intevation.de>
parents:
234
diff
changeset
|
38 CREATE SCHEMA internal |
72062ca52746
Make user_profiles table invisible for users
Tom Gottfried <tom@intevation.de>
parents:
234
diff
changeset
|
39 -- Profile data are only accessible via the view users.list_users. |
72062ca52746
Make user_profiles table invisible for users
Tom Gottfried <tom@intevation.de>
parents:
234
diff
changeset
|
40 CREATE TABLE user_profiles ( |
361
f5087cebc740
Enforce PostgreSQL identifier length on username
Tom Gottfried <tom@intevation.de>
parents:
345
diff
changeset
|
41 username varchar PRIMARY KEY CHECK(octet_length(username) <= 63), |
f5087cebc740
Enforce PostgreSQL identifier length on username
Tom Gottfried <tom@intevation.de>
parents:
345
diff
changeset
|
42 -- keep username length compatible with role identifier |
268
72062ca52746
Make user_profiles table invisible for users
Tom Gottfried <tom@intevation.de>
parents:
234
diff
changeset
|
43 map_extent box2d NOT NULL, |
72062ca52746
Make user_profiles table invisible for users
Tom Gottfried <tom@intevation.de>
parents:
234
diff
changeset
|
44 email_address varchar NOT NULL |
72062ca52746
Make user_profiles table invisible for users
Tom Gottfried <tom@intevation.de>
parents:
234
diff
changeset
|
45 ) |
72062ca52746
Make user_profiles table invisible for users
Tom Gottfried <tom@intevation.de>
parents:
234
diff
changeset
|
46 -- Columns referencing user-visible schemas added below. |
72062ca52746
Make user_profiles table invisible for users
Tom Gottfried <tom@intevation.de>
parents:
234
diff
changeset
|
47 ; |
72062ca52746
Make user_profiles table invisible for users
Tom Gottfried <tom@intevation.de>
parents:
234
diff
changeset
|
48 |
72062ca52746
Make user_profiles table invisible for users
Tom Gottfried <tom@intevation.de>
parents:
234
diff
changeset
|
49 |
195
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
50 -- Namespace to be accessed by sys_admin only |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
51 CREATE SCHEMA sys_admin |
457
62ffb6c8a42e
Remove unnecessary schema qualifiers
Tom Gottfried <tom@intevation.de>
parents:
449
diff
changeset
|
52 CREATE TABLE system_config ( |
195
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
53 config_key varchar PRIMARY KEY, |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
54 config_val varchar |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
55 ) |
437
b8366b24dc55
Added two tables to configure the WFS/WMS services of gemma.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
383
diff
changeset
|
56 |
478
3af7ca761f6a
Purge password reset role
Tom Gottfried <tom@intevation.de>
parents:
457
diff
changeset
|
57 CREATE TABLE password_reset_requests ( |
3af7ca761f6a
Purge password reset role
Tom Gottfried <tom@intevation.de>
parents:
457
diff
changeset
|
58 hash varchar(32) PRIMARY KEY, |
3af7ca761f6a
Purge password reset role
Tom Gottfried <tom@intevation.de>
parents:
457
diff
changeset
|
59 issued timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, |
3af7ca761f6a
Purge password reset role
Tom Gottfried <tom@intevation.de>
parents:
457
diff
changeset
|
60 username varchar NOT NULL |
3af7ca761f6a
Purge password reset role
Tom Gottfried <tom@intevation.de>
parents:
457
diff
changeset
|
61 REFERENCES internal.user_profiles(username) |
3af7ca761f6a
Purge password reset role
Tom Gottfried <tom@intevation.de>
parents:
457
diff
changeset
|
62 ON DELETE CASCADE ON UPDATE CASCADE |
3af7ca761f6a
Purge password reset role
Tom Gottfried <tom@intevation.de>
parents:
457
diff
changeset
|
63 ) |
3af7ca761f6a
Purge password reset role
Tom Gottfried <tom@intevation.de>
parents:
457
diff
changeset
|
64 |
624
8772979f8750
Remove test data from schema
Tom Gottfried <tom@intevation.de>
parents:
611
diff
changeset
|
65 -- Tables with geo data to be published with GeoServer. |
457
62ffb6c8a42e
Remove unnecessary schema qualifiers
Tom Gottfried <tom@intevation.de>
parents:
449
diff
changeset
|
66 CREATE TABLE external_services ( |
437
b8366b24dc55
Added two tables to configure the WFS/WMS services of gemma.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
383
diff
changeset
|
67 local_name varchar PRIMARY KEY, |
b8366b24dc55
Added two tables to configure the WFS/WMS services of gemma.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
383
diff
changeset
|
68 remote_url varchar NOT NULL, |
b8366b24dc55
Added two tables to configure the WFS/WMS services of gemma.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
383
diff
changeset
|
69 is_wfs boolean NOT NULL DEFAULT TRUE |
b8366b24dc55
Added two tables to configure the WFS/WMS services of gemma.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
383
diff
changeset
|
70 ) |
b8366b24dc55
Added two tables to configure the WFS/WMS services of gemma.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
383
diff
changeset
|
71 |
457
62ffb6c8a42e
Remove unnecessary schema qualifiers
Tom Gottfried <tom@intevation.de>
parents:
449
diff
changeset
|
72 CREATE TABLE published_services ( |
598
4854a1e85870
Ensure published service is based on existing table
Tom Gottfried <tom@intevation.de>
parents:
580
diff
changeset
|
73 name regclass PRIMARY KEY, |
1288
9f7dc950ffd2
Accept only well-formed XML documents as style in database
Tom Gottfried <tom@intevation.de>
parents:
1194
diff
changeset
|
74 style xml CHECK(style IS DOCUMENT), |
437
b8366b24dc55
Added two tables to configure the WFS/WMS services of gemma.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
383
diff
changeset
|
75 as_wms boolean NOT NULL DEFAULT TRUE, |
b8366b24dc55
Added two tables to configure the WFS/WMS services of gemma.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
383
diff
changeset
|
76 as_wfs boolean NOT NULL DEFAULT TRUE |
b8366b24dc55
Added two tables to configure the WFS/WMS services of gemma.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
383
diff
changeset
|
77 ) |
195
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
78 ; |
81
acaa485c0c1e
Use different schemas for different diagrams. Add TODOs.
Tom Gottfried <tom@intevation.de>
parents:
80
diff
changeset
|
79 |
acaa485c0c1e
Use different schemas for different diagrams. Add TODOs.
Tom Gottfried <tom@intevation.de>
parents:
80
diff
changeset
|
80 -- |
195
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
81 -- Look-up tables with data that are static in a running system |
81
acaa485c0c1e
Use different schemas for different diagrams. Add TODOs.
Tom Gottfried <tom@intevation.de>
parents:
80
diff
changeset
|
82 -- |
195
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
83 CREATE TABLE countries ( |
182 | 84 country_code char(2) PRIMARY KEY -- ISO 3166 country code |
85 -- A smallint PK would require even less disk space i.e. on the FK side. | |
86 -- This might be an issue in case cache space becomes a limiting | |
87 -- factor when there are many FKs pointing here. | |
88 ); | |
82 | 89 |
195
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
90 CREATE TABLE language_codes ( |
182 | 91 language_code varchar PRIMARY KEY |
92 ); | |
84
d905022a48e9
More user attributes from APUC3.
Tom Gottfried <tom@intevation.de>
parents:
83
diff
changeset
|
93 |
195
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
94 CREATE TABLE catccls ( |
182 | 95 catccl smallint PRIMARY KEY |
96 -- TODO: Do we need name and/or definition from IENC feature catalogue? | |
927
48f70782400d
Add categories of CEMT class and directions of impact
Tom Gottfried <tom@intevation.de>
parents:
919
diff
changeset
|
97 -- (see page 328 of edition 2.3) |
182 | 98 ); |
927
48f70782400d
Add categories of CEMT class and directions of impact
Tom Gottfried <tom@intevation.de>
parents:
919
diff
changeset
|
99 INSERT INTO catccls VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11); |
85
1a640da943b6
Add waterway area attributes.
Tom Gottfried <tom@intevation.de>
parents:
84
diff
changeset
|
100 |
195
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
101 CREATE TABLE dirimps ( |
182 | 102 dirimp smallint PRIMARY KEY |
103 -- TODO: Do we need name and/or definition from IENC feature catalogue? | |
927
48f70782400d
Add categories of CEMT class and directions of impact
Tom Gottfried <tom@intevation.de>
parents:
919
diff
changeset
|
104 -- (see page 381 of edition 2.3) |
182 | 105 ); |
927
48f70782400d
Add categories of CEMT class and directions of impact
Tom Gottfried <tom@intevation.de>
parents:
919
diff
changeset
|
106 INSERT INTO dirimps VALUES (1), (2), (3), (4); |
48f70782400d
Add categories of CEMT class and directions of impact
Tom Gottfried <tom@intevation.de>
parents:
919
diff
changeset
|
107 -- dirimp_5 left out because it cannot be used for waterway area |
85
1a640da943b6
Add waterway area attributes.
Tom Gottfried <tom@intevation.de>
parents:
84
diff
changeset
|
108 |
195
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
109 CREATE TABLE depth_references ( |
182 | 110 depth_reference varchar(4) PRIMARY KEY |
111 -- See col. AB and AI RIS-Index Encoding Guide | |
112 -- XXX: We need a way to distinguish between geodetic (eg. col. AP | |
113 -- RIS-Index) and other references (e.g. col. AB and AI): | |
114 -- _ multi-column FK with a boolean column (geodetic/non-geodetic; | |
115 -- i.e. absolut/not absolut) and DEFAULTs and CHECKs at the FK side. | |
116 -- _ Do not mixup things with different meanings in one table at all | |
117 -- (which would mean a model differing a bit from RIS-Index ideas) | |
118 ); | |
93 | 119 |
195
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
120 CREATE TABLE reference_water_levels ( |
182 | 121 reference_water_level varchar(20) PRIMARY KEY |
122 ); | |
70
28108455ad35
Add reference water levels to gauges.
Tom Gottfried <tom@intevation.de>
parents:
69
diff
changeset
|
123 |
934
e6220a19f284
Add categories of distance marks
Tom Gottfried <tom@intevation.de>
parents:
930
diff
changeset
|
124 CREATE TABLE catdis ( |
e6220a19f284
Add categories of distance marks
Tom Gottfried <tom@intevation.de>
parents:
930
diff
changeset
|
125 catdis smallint PRIMARY KEY |
e6220a19f284
Add categories of distance marks
Tom Gottfried <tom@intevation.de>
parents:
930
diff
changeset
|
126 -- TODO: Do we need name and/or definition from IENC feature catalogue? |
e6220a19f284
Add categories of distance marks
Tom Gottfried <tom@intevation.de>
parents:
930
diff
changeset
|
127 -- (see page 171 of edition 2.3) |
182 | 128 ); |
934
e6220a19f284
Add categories of distance marks
Tom Gottfried <tom@intevation.de>
parents:
930
diff
changeset
|
129 INSERT INTO catdis VALUES (1), (2), (3), (4); |
78
012948f18faa
Distance marks as link between 1D and 2D.
Tom Gottfried <tom@intevation.de>
parents:
77
diff
changeset
|
130 |
195
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
131 CREATE TABLE position_codes ( |
182 | 132 position_code char(2) PRIMARY KEY |
133 -- Use smallint because of fairway availability provided on daily basis? | |
134 -- Data come from 2015_06_23_RIS_Index_template_v2p0.xlsx, | |
135 -- sheet "Position_code" or RIS-Index encoding guide? | |
136 -- XXX: DRC 2.1.7 and 2.2.5 _seem_ to reference the same thing here. | |
137 -- Clarify! | |
138 -- TODO: Do we need an attribute "meaning" or so? | |
139 ); | |
87
c46fb3f1faeb
Add distance mark attributes and try to consolidate.
Tom Gottfried <tom@intevation.de>
parents:
86
diff
changeset
|
140 |
195
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
141 CREATE TABLE levels_of_service ( |
1662
d8ca44615bfc
Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1642
diff
changeset
|
142 level_of_service smallint PRIMARY KEY, |
d8ca44615bfc
Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1642
diff
changeset
|
143 name varchar(4) |
182 | 144 ); |
1662
d8ca44615bfc
Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1642
diff
changeset
|
145 INSERT INTO levels_of_service ( |
d8ca44615bfc
Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1642
diff
changeset
|
146 level_of_service, |
d8ca44615bfc
Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1642
diff
changeset
|
147 name |
d8ca44615bfc
Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1642
diff
changeset
|
148 ) VALUES (1, 'LOS1'), (2, 'LOS2'), (3, 'LOS3'); |
89
a36bfec5edd3
Move more tables to waterway schema to tweak diagrams.
Tom Gottfried <tom@intevation.de>
parents:
88
diff
changeset
|
149 |
195
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
150 CREATE TABLE riverbed_materials ( |
182 | 151 material varchar PRIMARY KEY |
152 -- XXX: Should this table contain choices from DRC 2.2.3 or | |
153 -- from IENC Encoding Guide M.4.3, attribute NATSUR? | |
154 ); | |
35
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
155 |
195
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
156 CREATE TABLE survey_types ( |
182 | 157 survey_type varchar PRIMARY KEY |
158 ); | |
35
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
159 |
195
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
160 CREATE TABLE coverage_types ( |
182 | 161 coverage_type varchar PRIMARY KEY |
162 ); | |
35
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
163 |
577
e6c9d2da2e20
Backed out changeset f3452ce5c056
Tom Gottfried <tom@intevation.de>
parents:
569
diff
changeset
|
164 CREATE TABLE limiting_factors ( |
e6c9d2da2e20
Backed out changeset f3452ce5c056
Tom Gottfried <tom@intevation.de>
parents:
569
diff
changeset
|
165 limiting_factor varchar PRIMARY KEY |
e6c9d2da2e20
Backed out changeset f3452ce5c056
Tom Gottfried <tom@intevation.de>
parents:
569
diff
changeset
|
166 ); |
e6c9d2da2e20
Backed out changeset f3452ce5c056
Tom Gottfried <tom@intevation.de>
parents:
569
diff
changeset
|
167 |
195
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
168 CREATE TABLE measure_types ( |
182 | 169 measure_type varchar PRIMARY KEY |
170 ); | |
58
30cb2f87c268
Add effective fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
56
diff
changeset
|
171 |
195
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
172 |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
173 -- Namespace for user management related data |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
174 CREATE SCHEMA users |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
175 CREATE TABLE responsibility_areas ( |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
176 country char(2) PRIMARY KEY REFERENCES countries, |
370
fe87457a05d7
Store spatial data as geography
Tom Gottfried <tom@intevation.de>
parents:
368
diff
changeset
|
177 area geography(MULTIPOLYGON, 4326) |
195
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
178 ) |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
179 |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
180 CREATE TABLE templates ( |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
181 template_name varchar PRIMARY KEY, |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
182 template_data bytea NOT NULL, |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
183 date_info timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
184 ) |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
185 CREATE TRIGGER templates_date_info BEFORE UPDATE ON templates |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
186 FOR EACH ROW EXECUTE PROCEDURE update_date_info() |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
187 |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
188 CREATE TABLE user_templates ( |
225
8b9cae6d3a21
Add database function to update role and user profile
Tom Gottfried <tom@intevation.de>
parents:
212
diff
changeset
|
189 username varchar NOT NULL |
268
72062ca52746
Make user_profiles table invisible for users
Tom Gottfried <tom@intevation.de>
parents:
234
diff
changeset
|
190 REFERENCES internal.user_profiles |
72062ca52746
Make user_profiles table invisible for users
Tom Gottfried <tom@intevation.de>
parents:
234
diff
changeset
|
191 ON DELETE CASCADE ON UPDATE CASCADE, |
195
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
192 template_name varchar NOT NULL REFERENCES templates ON DELETE CASCADE, |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
193 PRIMARY KEY (username, template_name) |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
194 ) |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
195 ; |
268
72062ca52746
Make user_profiles table invisible for users
Tom Gottfried <tom@intevation.de>
parents:
234
diff
changeset
|
196 ALTER TABLE internal.user_profiles ADD |
72062ca52746
Make user_profiles table invisible for users
Tom Gottfried <tom@intevation.de>
parents:
234
diff
changeset
|
197 country char(2) NOT NULL REFERENCES users.responsibility_areas; |
195
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
198 |
319
ac760b0f22a9
Add special role for password reset
Tom Gottfried <tom@intevation.de>
parents:
268
diff
changeset
|
199 |
831
fa417ff1f355
Extended schema to save feature style information.
Sascha Wilde <wilde@intevation.de>
parents:
821
diff
changeset
|
200 -- Namespace for system wide configuration |
fa417ff1f355
Extended schema to save feature style information.
Sascha Wilde <wilde@intevation.de>
parents:
821
diff
changeset
|
201 CREATE SCHEMA systemconf |
fa417ff1f355
Extended schema to save feature style information.
Sascha Wilde <wilde@intevation.de>
parents:
821
diff
changeset
|
202 CREATE TABLE feature_colours ( |
fa417ff1f355
Extended schema to save feature style information.
Sascha Wilde <wilde@intevation.de>
parents:
821
diff
changeset
|
203 feature_name varchar, |
fa417ff1f355
Extended schema to save feature style information.
Sascha Wilde <wilde@intevation.de>
parents:
821
diff
changeset
|
204 style_attr varchar, |
fa417ff1f355
Extended schema to save feature style information.
Sascha Wilde <wilde@intevation.de>
parents:
821
diff
changeset
|
205 r int NOT NULL CHECK (r >= 0 AND r < 256), |
fa417ff1f355
Extended schema to save feature style information.
Sascha Wilde <wilde@intevation.de>
parents:
821
diff
changeset
|
206 g int NOT NULL CHECK (g >= 0 AND g < 256), |
fa417ff1f355
Extended schema to save feature style information.
Sascha Wilde <wilde@intevation.de>
parents:
821
diff
changeset
|
207 b int NOT NULL CHECK (b >= 0 AND b < 256), |
fa417ff1f355
Extended schema to save feature style information.
Sascha Wilde <wilde@intevation.de>
parents:
821
diff
changeset
|
208 a numeric NOT NULL CHECK (a >= 0 AND a <= 1), |
fa417ff1f355
Extended schema to save feature style information.
Sascha Wilde <wilde@intevation.de>
parents:
821
diff
changeset
|
209 PRIMARY KEY (feature_name, style_attr) |
fa417ff1f355
Extended schema to save feature style information.
Sascha Wilde <wilde@intevation.de>
parents:
821
diff
changeset
|
210 ) |
fa417ff1f355
Extended schema to save feature style information.
Sascha Wilde <wilde@intevation.de>
parents:
821
diff
changeset
|
211 ; |
fa417ff1f355
Extended schema to save feature style information.
Sascha Wilde <wilde@intevation.de>
parents:
821
diff
changeset
|
212 |
195
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
213 -- Namespace for waterway data that can change in a running system |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
214 CREATE SCHEMA waterway |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
215 |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
216 -- Eventually obsolete. |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
217 -- See https://roundup-intern.intevation.de/gemma/issue5 |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
218 -- CREATE TABLE rwdrs ( |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
219 -- tretch isrsrange PRIMARY KEY, |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
220 -- -- https://www.postgresql.org/docs/10/static/sql-createindex.html: |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
221 -- -- Only B-tree supports UNIQUE indexes, but we need the GIST index |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
222 -- -- below anyhow. |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
223 -- -- Is it a good idea to build B-tree indexes on relatively large |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
224 -- -- composites of string values or should we use inter PKs? |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
225 -- -- => In case the index is used and cache space becomes a limiting |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
226 -- -- factor, this might be an issue. |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
227 -- rwdr double precision NOT NULL, |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
228 -- EXCLUDE USING GIST (stretch WITH &&) |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
229 --) |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
230 |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
231 CREATE TABLE waterway_area ( |
383
84597b9da68e
Let all tables have a PRIMARY KEY again
Tom Gottfried <tom@intevation.de>
parents:
371
diff
changeset
|
232 id int PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, |
371
d5b707bbd1d5
Do not create B-Tree indexes on potentially large spatial data
Tom Gottfried <tom@intevation.de>
parents:
370
diff
changeset
|
233 area geography(POLYGON, 4326) NOT NULL, |
195
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
234 catccl smallint REFERENCES catccls, |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
235 dirimp smallint REFERENCES dirimps |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
236 ) |
56
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
237 |
195
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
238 CREATE TABLE gauges ( |
1825
484ae4fe09d7
Backed out changeset 332e42a2088d (no staging needed).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1824
diff
changeset
|
239 location isrs PRIMARY KEY CHECK( |
579
642df1164aca
Ensure gauges are identified by appropriate ISRS location code
Tom Gottfried <tom@intevation.de>
parents:
577
diff
changeset
|
240 (location).orc SIMILAR TO 'G[[:digit:]]{4}' |
642df1164aca
Ensure gauges are identified by appropriate ISRS location code
Tom Gottfried <tom@intevation.de>
parents:
577
diff
changeset
|
241 AND CAST(substring((location).orc from 2 for 4) AS int) < 2048), |
195
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
242 objname varchar NOT NULL, |
370
fe87457a05d7
Store spatial data as geography
Tom Gottfried <tom@intevation.de>
parents:
368
diff
changeset
|
243 geom geography(POINT, 4326) NOT NULL, |
1826
d4e2637eed58
Schema: Adjust gauges once again to be in sync with RIS index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1825
diff
changeset
|
244 applicability_from_km int8, |
d4e2637eed58
Schema: Adjust gauges once again to be in sync with RIS index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1825
diff
changeset
|
245 applicability_to_km int8, |
d4e2637eed58
Schema: Adjust gauges once again to be in sync with RIS index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1825
diff
changeset
|
246 validity tstzrange, |
195
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
247 -- pasted text from a more general specification is given |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
248 -- (a gauge is not a berth!) |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
249 -- TODO: Ranges need a joint exclusion constaint to prevent overlaps? |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
250 zero_point double precision NOT NULL, |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
251 geodref varchar(4) REFERENCES depth_references, |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
252 date_info timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, |
1826
d4e2637eed58
Schema: Adjust gauges once again to be in sync with RIS index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1825
diff
changeset
|
253 source_organization varchar |
195
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
254 ) |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
255 CREATE TRIGGER gauges_date_info BEFORE UPDATE ON gauges |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
256 FOR EACH ROW EXECUTE PROCEDURE update_date_info() |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
257 |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
258 CREATE TABLE gauges_reference_water_levels ( |
1825
484ae4fe09d7
Backed out changeset 332e42a2088d (no staging needed).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1824
diff
changeset
|
259 gauge_id isrs NOT NULL REFERENCES gauges, |
195
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
260 reference_water_level varchar(20) |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
261 NOT NULL REFERENCES reference_water_levels, |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
262 PRIMARY KEY (gauge_id, reference_water_level), |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
263 value int NOT NULL |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
264 ) |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
265 |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
266 CREATE TABLE gauge_measurements ( |
1636
37ee25bc2bbe
Updated database schema for gauge meaurement imports.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1583
diff
changeset
|
267 id int PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, |
1825
484ae4fe09d7
Backed out changeset 332e42a2088d (no staging needed).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1824
diff
changeset
|
268 fk_gauge_id isrs NOT NULL REFERENCES gauges, |
195
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
269 measure_date timestamp with time zone NOT NULL, |
1636
37ee25bc2bbe
Updated database schema for gauge meaurement imports.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1583
diff
changeset
|
270 country_code char(2) NOT NULL REFERENCES countries, |
195
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
271 -- TODO: add relations to stuff provided as enumerations |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
272 sender varchar NOT NULL, -- "from" attribute from DRC |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
273 language_code varchar NOT NULL REFERENCES language_codes, |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
274 date_issue timestamp with time zone NOT NULL, |
1775
fcb0106ec510
Gauge measurement import: Added reference_code column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1759
diff
changeset
|
275 reference_code varchar(4) NOT NULL REFERENCES depth_references, |
195
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
276 water_level double precision NOT NULL, |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
277 predicted boolean NOT NULL, |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
278 is_waterlevel boolean NOT NULL, |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
279 -- XXX: "measure_code" if really only W or Q |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
280 -- XXX: Do we need "unit" attribute or can we normalise on import? |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
281 value_min double precision, -- XXX: NOT NULL if predicted? |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
282 value_max double precision, -- XXX: NOT NULL if predicted? |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
283 --- TODO: Add a double range type for checking? |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
284 date_info timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, |
1780
48791416bea5
(Approved) gauge measurement import: Fixed row level security.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1775
diff
changeset
|
285 source_organization varchar NOT NULL, -- "originator" |
1783
8fd132b9cdbd
Gauge measurements: Add an unique constraint so there could only
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1780
diff
changeset
|
286 staging_done boolean NOT NULL DEFAULT false, |
8fd132b9cdbd
Gauge measurements: Add an unique constraint so there could only
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1780
diff
changeset
|
287 -- So we can have a staged and |
8fd132b9cdbd
Gauge measurements: Add an unique constraint so there could only
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1780
diff
changeset
|
288 -- a non-staged fk_gauge_id/measure_date pair. |
8fd132b9cdbd
Gauge measurements: Add an unique constraint so there could only
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1780
diff
changeset
|
289 UNIQUE (fk_gauge_id, measure_date, staging_done) |
195
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
290 ) |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
291 CREATE TRIGGER gauge_measurements_date_info |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
292 BEFORE UPDATE ON gauge_measurements |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
293 FOR EACH ROW EXECUTE PROCEDURE update_date_info() |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
294 |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
295 CREATE TABLE waterway_axis ( |
383
84597b9da68e
Let all tables have a PRIMARY KEY again
Tom Gottfried <tom@intevation.de>
parents:
371
diff
changeset
|
296 id int PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, |
371
d5b707bbd1d5
Do not create B-Tree indexes on potentially large spatial data
Tom Gottfried <tom@intevation.de>
parents:
370
diff
changeset
|
297 wtwaxs geography(LINESTRING, 4326) NOT NULL, |
195
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
298 -- TODO: Do we need to check data set quality (DRC 2.1.6)? |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
299 objnam varchar NOT NULL, |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
300 nobjnam varchar |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
301 ) |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
302 |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
303 -- This table allows linkage between 1D ISRS location codes and 2D space |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
304 -- e.g. for cutting bottleneck area out of waterway area based on virtual |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
305 -- distance marks along waterway axis (see SUC7). |
948
5f89868bd75e
Store virtual and physical distance marks separately
Tom Gottfried <tom@intevation.de>
parents:
944
diff
changeset
|
306 CREATE TABLE distance_marks_virtual ( |
195
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
307 location_code isrs PRIMARY KEY, |
370
fe87457a05d7
Store spatial data as geography
Tom Gottfried <tom@intevation.de>
parents:
368
diff
changeset
|
308 geom geography(POINT, 4326) NOT NULL, |
948
5f89868bd75e
Store virtual and physical distance marks separately
Tom Gottfried <tom@intevation.de>
parents:
944
diff
changeset
|
309 related_enc varchar(12) NOT NULL |
5f89868bd75e
Store virtual and physical distance marks separately
Tom Gottfried <tom@intevation.de>
parents:
944
diff
changeset
|
310 ) |
5f89868bd75e
Store virtual and physical distance marks separately
Tom Gottfried <tom@intevation.de>
parents:
944
diff
changeset
|
311 |
5f89868bd75e
Store virtual and physical distance marks separately
Tom Gottfried <tom@intevation.de>
parents:
944
diff
changeset
|
312 CREATE TABLE distance_marks ( |
1861
5083a1d19a4b
Adjusted database schema for distance marks importer.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1831
diff
changeset
|
313 id int PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, |
5083a1d19a4b
Adjusted database schema for distance marks importer.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1831
diff
changeset
|
314 country char(2) REFERENCES countries, |
5083a1d19a4b
Adjusted database schema for distance marks importer.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1831
diff
changeset
|
315 hectom int, |
948
5f89868bd75e
Store virtual and physical distance marks separately
Tom Gottfried <tom@intevation.de>
parents:
944
diff
changeset
|
316 geom geography(POINT, 4326) NOT NULL, |
5f89868bd75e
Store virtual and physical distance marks separately
Tom Gottfried <tom@intevation.de>
parents:
944
diff
changeset
|
317 -- include location in primary key, because we have no fairway code: |
1861
5083a1d19a4b
Adjusted database schema for distance marks importer.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1831
diff
changeset
|
318 catdis smallint REFERENCES catdis, |
5083a1d19a4b
Adjusted database schema for distance marks importer.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1831
diff
changeset
|
319 position_code char(2) REFERENCES position_codes, |
5083a1d19a4b
Adjusted database schema for distance marks importer.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1831
diff
changeset
|
320 related_enc varchar(12) |
195
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
321 ) |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
322 |
690
f595b3455d75
Schema: Add view for waterway axis
Bernhard Reiter <bernhard@intevation.de>
parents:
659
diff
changeset
|
323 -- A table to help geoserver serve the distance marks as WFS 1.1.0. |
f595b3455d75
Schema: Add view for waterway axis
Bernhard Reiter <bernhard@intevation.de>
parents:
659
diff
changeset
|
324 -- At least geoserver-2.13.2 does not serve type geography correctly |
f595b3455d75
Schema: Add view for waterway axis
Bernhard Reiter <bernhard@intevation.de>
parents:
659
diff
changeset
|
325 -- and does not serve the location_code as isrs type |
1831
74a3d8d8939e
Remove superfluous schema qualifiers in definition of the schema itself
Tom Gottfried <tom@intevation.de>
parents:
1826
diff
changeset
|
326 CREATE VIEW distance_marks_geoserver AS |
690
f595b3455d75
Schema: Add view for waterway axis
Bernhard Reiter <bernhard@intevation.de>
parents:
659
diff
changeset
|
327 SELECT location_code::VARCHAR, |
f595b3455d75
Schema: Add view for waterway axis
Bernhard Reiter <bernhard@intevation.de>
parents:
659
diff
changeset
|
328 geom::Geometry(POINT, 4326), |
948
5f89868bd75e
Store virtual and physical distance marks separately
Tom Gottfried <tom@intevation.de>
parents:
944
diff
changeset
|
329 related_enc, |
690
f595b3455d75
Schema: Add view for waterway axis
Bernhard Reiter <bernhard@intevation.de>
parents:
659
diff
changeset
|
330 (location_code).hectometre |
1831
74a3d8d8939e
Remove superfluous schema qualifiers in definition of the schema itself
Tom Gottfried <tom@intevation.de>
parents:
1826
diff
changeset
|
331 FROM distance_marks_virtual |
690
f595b3455d75
Schema: Add view for waterway axis
Bernhard Reiter <bernhard@intevation.de>
parents:
659
diff
changeset
|
332 |
1446
1e19184472bf
Add configuration of primary key metadata used by geoserver.
Sascha Wilde <wilde@intevation.de>
parents:
1392
diff
changeset
|
333 -- We need to configure primary keys for the views used by |
1e19184472bf
Add configuration of primary key metadata used by geoserver.
Sascha Wilde <wilde@intevation.de>
parents:
1392
diff
changeset
|
334 -- geoserver for wfs, otherwise it will generate ids on the fly, |
1e19184472bf
Add configuration of primary key metadata used by geoserver.
Sascha Wilde <wilde@intevation.de>
parents:
1392
diff
changeset
|
335 -- which will change for the same feature... |
1e19184472bf
Add configuration of primary key metadata used by geoserver.
Sascha Wilde <wilde@intevation.de>
parents:
1392
diff
changeset
|
336 -- See |
1e19184472bf
Add configuration of primary key metadata used by geoserver.
Sascha Wilde <wilde@intevation.de>
parents:
1392
diff
changeset
|
337 -- https://docs.geoserver.org/stable/en/user/data/database/primarykey.html |
1e19184472bf
Add configuration of primary key metadata used by geoserver.
Sascha Wilde <wilde@intevation.de>
parents:
1392
diff
changeset
|
338 -- for details. |
1e19184472bf
Add configuration of primary key metadata used by geoserver.
Sascha Wilde <wilde@intevation.de>
parents:
1392
diff
changeset
|
339 CREATE TABLE gt_pk_metadata ( |
1e19184472bf
Add configuration of primary key metadata used by geoserver.
Sascha Wilde <wilde@intevation.de>
parents:
1392
diff
changeset
|
340 table_schema VARCHAR(32) NOT NULL, |
1e19184472bf
Add configuration of primary key metadata used by geoserver.
Sascha Wilde <wilde@intevation.de>
parents:
1392
diff
changeset
|
341 table_name VARCHAR(32) NOT NULL, |
1e19184472bf
Add configuration of primary key metadata used by geoserver.
Sascha Wilde <wilde@intevation.de>
parents:
1392
diff
changeset
|
342 pk_column VARCHAR(32) NOT NULL, |
1e19184472bf
Add configuration of primary key metadata used by geoserver.
Sascha Wilde <wilde@intevation.de>
parents:
1392
diff
changeset
|
343 pk_column_idx INTEGER, |
1e19184472bf
Add configuration of primary key metadata used by geoserver.
Sascha Wilde <wilde@intevation.de>
parents:
1392
diff
changeset
|
344 pk_policy VARCHAR(32), |
1e19184472bf
Add configuration of primary key metadata used by geoserver.
Sascha Wilde <wilde@intevation.de>
parents:
1392
diff
changeset
|
345 pk_sequence VARCHAR(64), |
1e19184472bf
Add configuration of primary key metadata used by geoserver.
Sascha Wilde <wilde@intevation.de>
parents:
1392
diff
changeset
|
346 unique (table_schema, table_name, pk_column), |
1e19184472bf
Add configuration of primary key metadata used by geoserver.
Sascha Wilde <wilde@intevation.de>
parents:
1392
diff
changeset
|
347 check (pk_policy in ('sequence', 'assigned', 'autogenerated')) |
1e19184472bf
Add configuration of primary key metadata used by geoserver.
Sascha Wilde <wilde@intevation.de>
parents:
1392
diff
changeset
|
348 ) |
1e19184472bf
Add configuration of primary key metadata used by geoserver.
Sascha Wilde <wilde@intevation.de>
parents:
1392
diff
changeset
|
349 |
1894
d72a1539ef3c
Schema: Replaced sections_stretches table with a pure stretches table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1861
diff
changeset
|
350 CREATE TABLE stretches ( |
d72a1539ef3c
Schema: Replaced sections_stretches table with a pure stretches table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1861
diff
changeset
|
351 id int PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, |
d72a1539ef3c
Schema: Replaced sections_stretches table with a pure stretches table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1861
diff
changeset
|
352 name varchar NOT NULL, |
d72a1539ef3c
Schema: Replaced sections_stretches table with a pure stretches table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1861
diff
changeset
|
353 stretch isrsrange NOT NULL, |
1983
f9f1babe52ae
Fix area generation from multipolygon input
Tom Gottfried <tom@intevation.de>
parents:
1975
diff
changeset
|
354 area geography(MULTIPOLYGON, 4326) NOT NULL, |
195
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
355 objnam varchar NOT NULL, |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
356 nobjnam varchar, |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
357 date_info timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, |
345
b97b3172c61a
Add staging feature to more tables
Tom Gottfried <tom@intevation.de>
parents:
323
diff
changeset
|
358 source_organization varchar NOT NULL, |
1894
d72a1539ef3c
Schema: Replaced sections_stretches table with a pure stretches table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1861
diff
changeset
|
359 staging_done boolean NOT NULL DEFAULT false, |
d72a1539ef3c
Schema: Replaced sections_stretches table with a pure stretches table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1861
diff
changeset
|
360 UNIQUE(name, staging_done) |
195
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
361 ) |
1894
d72a1539ef3c
Schema: Replaced sections_stretches table with a pure stretches table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1861
diff
changeset
|
362 |
d72a1539ef3c
Schema: Replaced sections_stretches table with a pure stretches table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1861
diff
changeset
|
363 CREATE TABLE stretch_countries ( |
1906
32c56e6c089a
Stretch import: Added forgotten source file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1894
diff
changeset
|
364 stretches_id int NOT NULL REFERENCES stretches(id) |
32c56e6c089a
Stretch import: Added forgotten source file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1894
diff
changeset
|
365 ON DELETE CASCADE, |
1894
d72a1539ef3c
Schema: Replaced sections_stretches table with a pure stretches table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1861
diff
changeset
|
366 country_code char(2) NOT NULL REFERENCES countries(country_code), |
d72a1539ef3c
Schema: Replaced sections_stretches table with a pure stretches table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1861
diff
changeset
|
367 UNIQUE(stretches_id, country_code) |
d72a1539ef3c
Schema: Replaced sections_stretches table with a pure stretches table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1861
diff
changeset
|
368 ) |
d72a1539ef3c
Schema: Replaced sections_stretches table with a pure stretches table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1861
diff
changeset
|
369 |
1929
f538d9a23329
Better suited GeoServer view for waterway.stretches.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1906
diff
changeset
|
370 -- Published view for GeoServer |
f538d9a23329
Better suited GeoServer view for waterway.stretches.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1906
diff
changeset
|
371 CREATE VIEW stretches_geoserver AS SELECT |
f538d9a23329
Better suited GeoServer view for waterway.stretches.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1906
diff
changeset
|
372 id, |
f538d9a23329
Better suited GeoServer view for waterway.stretches.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1906
diff
changeset
|
373 name, |
f538d9a23329
Better suited GeoServer view for waterway.stretches.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1906
diff
changeset
|
374 (stretch).lower::varchar as lower, |
f538d9a23329
Better suited GeoServer view for waterway.stretches.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1906
diff
changeset
|
375 (stretch).upper::varchar as upper, |
1983
f9f1babe52ae
Fix area generation from multipolygon input
Tom Gottfried <tom@intevation.de>
parents:
1975
diff
changeset
|
376 area::Geometry(MULTIPOLYGON, 4326), |
1929
f538d9a23329
Better suited GeoServer view for waterway.stretches.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1906
diff
changeset
|
377 objnam, |
f538d9a23329
Better suited GeoServer view for waterway.stretches.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1906
diff
changeset
|
378 nobjnam, |
f538d9a23329
Better suited GeoServer view for waterway.stretches.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1906
diff
changeset
|
379 date_info, |
f538d9a23329
Better suited GeoServer view for waterway.stretches.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1906
diff
changeset
|
380 source_organization, |
f538d9a23329
Better suited GeoServer view for waterway.stretches.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1906
diff
changeset
|
381 (SELECT string_agg(country_code, ', ') |
f538d9a23329
Better suited GeoServer view for waterway.stretches.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1906
diff
changeset
|
382 FROM stretch_countries |
f538d9a23329
Better suited GeoServer view for waterway.stretches.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1906
diff
changeset
|
383 WHERE stretches_id = id) AS countries, |
f538d9a23329
Better suited GeoServer view for waterway.stretches.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1906
diff
changeset
|
384 staging_done |
f538d9a23329
Better suited GeoServer view for waterway.stretches.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1906
diff
changeset
|
385 FROM stretches |
f538d9a23329
Better suited GeoServer view for waterway.stretches.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1906
diff
changeset
|
386 |
f538d9a23329
Better suited GeoServer view for waterway.stretches.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1906
diff
changeset
|
387 |
195
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
388 CREATE TRIGGER sections_stretches_date_info |
1894
d72a1539ef3c
Schema: Replaced sections_stretches table with a pure stretches table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1861
diff
changeset
|
389 BEFORE UPDATE ON stretches |
195
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
390 FOR EACH ROW EXECUTE PROCEDURE update_date_info() |
56
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
391 |
195
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
392 CREATE TABLE waterway_profiles ( |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
393 location isrs NOT NULL, |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
394 validity tstzrange, |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
395 EXCLUDE USING GIST (validity WITH &&), |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
396 PRIMARY KEY (location, validity), |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
397 lnwl smallint, |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
398 mwl smallint, |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
399 hnwl smallint, |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
400 fe30 smallint, |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
401 fe100 smallint, |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
402 -- XXX: further normalise using reference_water_levels? |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
403 CHECK(COALESCE(lnwl, mwl, hnwl, fe30, fe100) IS NULL |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
404 OR validity IS NOT NULL), |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
405 date_info timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, |
345
b97b3172c61a
Add staging feature to more tables
Tom Gottfried <tom@intevation.de>
parents:
323
diff
changeset
|
406 source_organization varchar NOT NULL, |
b97b3172c61a
Add staging feature to more tables
Tom Gottfried <tom@intevation.de>
parents:
323
diff
changeset
|
407 staging_done boolean NOT NULL DEFAULT false |
195
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
408 ) |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
409 CREATE TRIGGER waterway_profiles_date_info |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
410 BEFORE UPDATE ON waterway_profiles |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
411 FOR EACH ROW EXECUTE PROCEDURE update_date_info() |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
412 |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
413 CREATE TABLE fairway_dimensions ( |
383
84597b9da68e
Let all tables have a PRIMARY KEY again
Tom Gottfried <tom@intevation.de>
parents:
371
diff
changeset
|
414 id int PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, |
371
d5b707bbd1d5
Do not create B-Tree indexes on potentially large spatial data
Tom Gottfried <tom@intevation.de>
parents:
370
diff
changeset
|
415 area geography(POLYGON, 4326) NOT NULL, |
195
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
416 level_of_service smallint NOT NULL REFERENCES levels_of_service, |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
417 min_width smallint NOT NULL, |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
418 max_width smallint NOT NULL, |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
419 min_depth smallint NOT NULL, |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
420 date_info timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, |
345
b97b3172c61a
Add staging feature to more tables
Tom Gottfried <tom@intevation.de>
parents:
323
diff
changeset
|
421 source_organization varchar NOT NULL, |
b97b3172c61a
Add staging feature to more tables
Tom Gottfried <tom@intevation.de>
parents:
323
diff
changeset
|
422 staging_done boolean NOT NULL DEFAULT false |
195
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
423 ) |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
424 CREATE TRIGGER fairway_dimensions_date_info |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
425 BEFORE UPDATE ON fairway_dimensions |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
426 FOR EACH ROW EXECUTE PROCEDURE update_date_info() |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
427 |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
428 -- |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
429 -- Bottlenecks |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
430 -- |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
431 -- XXX: Nullability differs between DRC (attributes marked "O") and WSDL |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
432 -- (minOccurs=0; nillable seems to be set arbitrarily as even bottleneck_id and |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
433 -- fk_g_fid (both mandatory, i.e. marked "M" in DRC) have nillable="true" in WSDL) |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
434 CREATE TABLE bottlenecks ( |
1572
056a86b24be2
Made bottleneck primary key an int. Attention: This may break something!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1547
diff
changeset
|
435 id int PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, |
056a86b24be2
Made bottleneck primary key an int. Attention: This may break something!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1547
diff
changeset
|
436 bottleneck_id varchar UNIQUE NOT NULL, |
1825
484ae4fe09d7
Backed out changeset 332e42a2088d (no staging needed).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1824
diff
changeset
|
437 fk_g_fid isrs NOT NULL REFERENCES gauges, |
195
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
438 -- XXX: DRC references "ch. 3.1.1", which does not exist in document. |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
439 objnam varchar, |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
440 nobjnm varchar, |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
441 stretch isrsrange NOT NULL, |
1983
f9f1babe52ae
Fix area generation from multipolygon input
Tom Gottfried <tom@intevation.de>
parents:
1975
diff
changeset
|
442 area geography(MULTIPOLYGON, 4326) NOT NULL, |
195
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
443 rb char(2) NOT NULL REFERENCES countries, -- from rb_lb in interface |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
444 lb char(2) NOT NULL REFERENCES countries, -- from rb_lb in interface |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
445 responsible_country char(2) NOT NULL REFERENCES countries, |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
446 revisiting_time smallint NOT NULL, |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
447 limiting varchar NOT NULL REFERENCES limiting_factors, |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
448 -- surtyp varchar NOT NULL REFERENCES survey_types, |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
449 -- XXX: Also an attribut of sounding result? |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
450 -- coverage varchar REFERENCES coverage_types, |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
451 -- XXX: Also an attribut of sounding result? |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
452 -- CHECK allowed combinations of surtyp and coverage or |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
453 -- different model approach? |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
454 -- depth_reference char(3) NOT NULL REFERENCES depth_references, |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
455 -- XXX: Also an attribut of sounding result? |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
456 date_info timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
457 source_organization varchar NOT NULL, |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
458 -- additional_data xml -- Currently not relevant for GEMMA |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
459 staging_done boolean NOT NULL DEFAULT false |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
460 ) |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
461 CREATE TRIGGER bottleneck_date_info BEFORE UPDATE ON bottlenecks |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
462 FOR EACH ROW EXECUTE PROCEDURE update_date_info() |
56
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
463 |
195
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
464 CREATE TABLE bottlenecks_riverbed_materials ( |
1572
056a86b24be2
Made bottleneck primary key an int. Attention: This may break something!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1547
diff
changeset
|
465 bottleneck_id int REFERENCES bottlenecks(id), |
195
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
466 riverbed varchar REFERENCES riverbed_materials, |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
467 -- XXX: should be 'natsur' according to IENC Encoding Guide M.4.3 |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
468 PRIMARY KEY (bottleneck_id, riverbed) |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
469 ) |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
470 |
1963
f7a35ba9f409
Added view for publishing bottlenecks
Sascha Wilde <wilde@intevation.de>
parents:
1929
diff
changeset
|
471 -- Published view for GeoServer |
f7a35ba9f409
Added view for publishing bottlenecks
Sascha Wilde <wilde@intevation.de>
parents:
1929
diff
changeset
|
472 CREATE VIEW bottlenecks_geoserver AS SELECT |
f7a35ba9f409
Added view for publishing bottlenecks
Sascha Wilde <wilde@intevation.de>
parents:
1929
diff
changeset
|
473 b.bottleneck_id, |
f7a35ba9f409
Added view for publishing bottlenecks
Sascha Wilde <wilde@intevation.de>
parents:
1929
diff
changeset
|
474 b.objnam, |
f7a35ba9f409
Added view for publishing bottlenecks
Sascha Wilde <wilde@intevation.de>
parents:
1929
diff
changeset
|
475 b.nobjnm, |
f7a35ba9f409
Added view for publishing bottlenecks
Sascha Wilde <wilde@intevation.de>
parents:
1929
diff
changeset
|
476 b.stretch, |
f7a35ba9f409
Added view for publishing bottlenecks
Sascha Wilde <wilde@intevation.de>
parents:
1929
diff
changeset
|
477 b.area, |
f7a35ba9f409
Added view for publishing bottlenecks
Sascha Wilde <wilde@intevation.de>
parents:
1929
diff
changeset
|
478 b.rb, |
f7a35ba9f409
Added view for publishing bottlenecks
Sascha Wilde <wilde@intevation.de>
parents:
1929
diff
changeset
|
479 b.lb, |
f7a35ba9f409
Added view for publishing bottlenecks
Sascha Wilde <wilde@intevation.de>
parents:
1929
diff
changeset
|
480 b.responsible_country, |
f7a35ba9f409
Added view for publishing bottlenecks
Sascha Wilde <wilde@intevation.de>
parents:
1929
diff
changeset
|
481 b.revisiting_time, |
f7a35ba9f409
Added view for publishing bottlenecks
Sascha Wilde <wilde@intevation.de>
parents:
1929
diff
changeset
|
482 b.limiting, |
f7a35ba9f409
Added view for publishing bottlenecks
Sascha Wilde <wilde@intevation.de>
parents:
1929
diff
changeset
|
483 b.date_info, |
f7a35ba9f409
Added view for publishing bottlenecks
Sascha Wilde <wilde@intevation.de>
parents:
1929
diff
changeset
|
484 b.source_organization, |
f7a35ba9f409
Added view for publishing bottlenecks
Sascha Wilde <wilde@intevation.de>
parents:
1929
diff
changeset
|
485 g.location AS gauge_isrs_code, |
f7a35ba9f409
Added view for publishing bottlenecks
Sascha Wilde <wilde@intevation.de>
parents:
1929
diff
changeset
|
486 g.objname AS gauge_objname, |
f7a35ba9f409
Added view for publishing bottlenecks
Sascha Wilde <wilde@intevation.de>
parents:
1929
diff
changeset
|
487 grwl.reference_water_level, |
f7a35ba9f409
Added view for publishing bottlenecks
Sascha Wilde <wilde@intevation.de>
parents:
1929
diff
changeset
|
488 grwl.value AS reference_water_level_value |
f7a35ba9f409
Added view for publishing bottlenecks
Sascha Wilde <wilde@intevation.de>
parents:
1929
diff
changeset
|
489 FROM bottlenecks b, gauges g, gauges_reference_water_levels grwl |
f7a35ba9f409
Added view for publishing bottlenecks
Sascha Wilde <wilde@intevation.de>
parents:
1929
diff
changeset
|
490 WHERE b.fk_g_fid = g.location AND g.location = grwl.gauge_id |
f7a35ba9f409
Added view for publishing bottlenecks
Sascha Wilde <wilde@intevation.de>
parents:
1929
diff
changeset
|
491 |
195
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
492 CREATE TABLE sounding_results ( |
656
9ef2f80a4645
Fix syntax error in schema script
Tom Gottfried <tom@intevation.de>
parents:
655
diff
changeset
|
493 id int PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, |
1572
056a86b24be2
Made bottleneck primary key an int. Attention: This may break something!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1547
diff
changeset
|
494 bottleneck_id int NOT NULL REFERENCES bottlenecks(id), |
195
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
495 date_info date NOT NULL, |
656
9ef2f80a4645
Fix syntax error in schema script
Tom Gottfried <tom@intevation.de>
parents:
655
diff
changeset
|
496 UNIQUE (bottleneck_id, date_info), |
917
5b90217aa1bb
Fix nullability in sounding results
Tom Gottfried <tom@intevation.de>
parents:
916
diff
changeset
|
497 area geography(POLYGON, 4326) NOT NULL, |
611
effd22c0ae5a
Sounding result: Write simple SQL insert dumper. Not deterministic, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
609
diff
changeset
|
498 surtyp varchar REFERENCES survey_types, |
195
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
499 coverage varchar REFERENCES coverage_types, |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
500 depth_reference char(3) NOT NULL REFERENCES depth_references, |
917
5b90217aa1bb
Fix nullability in sounding results
Tom Gottfried <tom@intevation.de>
parents:
916
diff
changeset
|
501 point_cloud geography(MULTIPOINTZ, 4326) NOT NULL, |
1131
2e6b47cdb2ca
Store octrees along with sounding results
Tom Gottfried <tom@intevation.de>
parents:
1085
diff
changeset
|
502 octree_checksum varchar, |
2e6b47cdb2ca
Store octrees along with sounding results
Tom Gottfried <tom@intevation.de>
parents:
1085
diff
changeset
|
503 octree_index bytea, |
195
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
504 staging_done boolean NOT NULL DEFAULT false |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
505 ) |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
506 |
731
4d6329afc1ea
Added table for contour lines of sounding results.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
720
diff
changeset
|
507 CREATE TABLE sounding_results_contour_lines ( |
1133
dd4071019676
Delete contour lines with their sounding result
Tom Gottfried <tom@intevation.de>
parents:
1131
diff
changeset
|
508 sounding_result_id int NOT NULL REFERENCES sounding_results |
dd4071019676
Delete contour lines with their sounding result
Tom Gottfried <tom@intevation.de>
parents:
1131
diff
changeset
|
509 ON DELETE CASCADE, |
731
4d6329afc1ea
Added table for contour lines of sounding results.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
720
diff
changeset
|
510 height numeric NOT NULL, |
919
271561dce2e6
Store contour lines in 2D
Tom Gottfried <tom@intevation.de>
parents:
917
diff
changeset
|
511 lines geography(multilinestring, 4326) NOT NULL, |
1133
dd4071019676
Delete contour lines with their sounding result
Tom Gottfried <tom@intevation.de>
parents:
1131
diff
changeset
|
512 PRIMARY KEY (sounding_result_id, height) |
731
4d6329afc1ea
Added table for contour lines of sounding results.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
720
diff
changeset
|
513 ) |
821
d32516051d08
Add view to help geoserver serve contour lines
Tom Gottfried <tom@intevation.de>
parents:
736
diff
changeset
|
514 -- A view to help geoserver serve contour lines. |
d32516051d08
Add view to help geoserver serve contour lines
Tom Gottfried <tom@intevation.de>
parents:
736
diff
changeset
|
515 -- At least geoserver-2.13.2 does not serve type geography correctly |
1831
74a3d8d8939e
Remove superfluous schema qualifiers in definition of the schema itself
Tom Gottfried <tom@intevation.de>
parents:
1826
diff
changeset
|
516 CREATE VIEW sounding_results_contour_lines_geoserver AS |
821
d32516051d08
Add view to help geoserver serve contour lines
Tom Gottfried <tom@intevation.de>
parents:
736
diff
changeset
|
517 SELECT bottleneck_id, |
d32516051d08
Add view to help geoserver serve contour lines
Tom Gottfried <tom@intevation.de>
parents:
736
diff
changeset
|
518 date_info, |
d32516051d08
Add view to help geoserver serve contour lines
Tom Gottfried <tom@intevation.de>
parents:
736
diff
changeset
|
519 height, |
919
271561dce2e6
Store contour lines in 2D
Tom Gottfried <tom@intevation.de>
parents:
917
diff
changeset
|
520 CAST(lines AS geometry(multilinestring, 4326)) AS lines |
1831
74a3d8d8939e
Remove superfluous schema qualifiers in definition of the schema itself
Tom Gottfried <tom@intevation.de>
parents:
1826
diff
changeset
|
521 FROM sounding_results_contour_lines cl |
74a3d8d8939e
Remove superfluous schema qualifiers in definition of the schema itself
Tom Gottfried <tom@intevation.de>
parents:
1826
diff
changeset
|
522 JOIN sounding_results sr |
821
d32516051d08
Add view to help geoserver serve contour lines
Tom Gottfried <tom@intevation.de>
parents:
736
diff
changeset
|
523 ON sr.id = cl.sounding_result_id |
d32516051d08
Add view to help geoserver serve contour lines
Tom Gottfried <tom@intevation.de>
parents:
736
diff
changeset
|
524 |
195
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
525 -- |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
526 -- Fairway availability |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
527 -- |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
528 CREATE TABLE fairway_availability ( |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
529 id int PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
530 position_code char(2) REFERENCES position_codes, |
1572
056a86b24be2
Made bottleneck primary key an int. Attention: This may break something!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1547
diff
changeset
|
531 bottleneck_id int NOT NULL REFERENCES bottlenecks(id), |
195
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
532 surdat date NOT NULL, |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
533 UNIQUE (bottleneck_id, surdat), |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
534 -- additional_data xml -- Currently not relevant for GEMMA |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
535 critical boolean, |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
536 date_info timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
537 source_organization varchar NOT NULL |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
538 ) |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
539 CREATE TRIGGER fairway_availability_date_info |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
540 BEFORE UPDATE ON fairway_availability |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
541 FOR EACH ROW EXECUTE PROCEDURE update_date_info() |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
542 |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
543 CREATE TABLE fa_reference_values ( |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
544 fairway_availability_id int NOT NULL REFERENCES fairway_availability, |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
545 level_of_service smallint NOT NULL REFERENCES levels_of_service, |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
546 PRIMARY KEY (fairway_availability_id, level_of_service), |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
547 fairway_depth smallint, |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
548 fairway_width smallint, |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
549 fairway_radius int, |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
550 CHECK(COALESCE(fairway_depth, fairway_width, fairway_radius) |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
551 IS NOT NULL), |
370
fe87457a05d7
Store spatial data as geography
Tom Gottfried <tom@intevation.de>
parents:
368
diff
changeset
|
552 shallowest_spot geography(POINT, 4326) |
195
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
553 ) |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
554 |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
555 CREATE TABLE bottleneck_pdfs ( |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
556 fairway_availability_id int NOT NULL REFERENCES fairway_availability, |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
557 profile_pdf_filename varchar NOT NULL, -- redundant to last part of URL |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
558 profile_pdf_url varchar NOT NULL, -- prohibit insecure URLs somehow? |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
559 PRIMARY KEY (fairway_availability_id, profile_pdf_url), |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
560 pdf_generation_date timestamp with time zone NOT NULL, |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
561 source_organization varchar NOT NULL |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
562 ) |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
563 |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
564 CREATE TABLE effective_fairway_availability ( |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
565 fairway_availability_id int NOT NULL REFERENCES fairway_availability, |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
566 measure_date timestamp with time zone NOT NULL, |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
567 level_of_service smallint NOT NULL REFERENCES levels_of_service, |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
568 PRIMARY KEY (fairway_availability_id, measure_date, level_of_service), |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
569 available_depth_value smallint, |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
570 available_width_value smallint, |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
571 water_level_value smallint, |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
572 CHECK(COALESCE(available_depth_value, available_width_value, |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
573 water_level_value) IS NOT NULL), |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
574 measure_type varchar NOT NULL REFERENCES measure_types, |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
575 source_organization varchar NOT NULL, |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
576 forecast_generation_time timestamp with time zone, |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
577 CHECK(measure_type <> 'forecasted' |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
578 OR forecast_generation_time IS NOT NULL), |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
579 value_lifetime timestamp with time zone, |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
580 CHECK(measure_type = 'minimum guaranteed' |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
581 OR value_lifetime IS NOT NULL) |
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
582 ) |
1085
72cad6277e3a
Added waterway.bottleneck_overview view to database schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1012
diff
changeset
|
583 |
1831
74a3d8d8939e
Remove superfluous schema qualifiers in definition of the schema itself
Tom Gottfried <tom@intevation.de>
parents:
1826
diff
changeset
|
584 CREATE VIEW bottleneck_overview AS |
1085
72cad6277e3a
Added waterway.bottleneck_overview view to database schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1012
diff
changeset
|
585 SELECT |
72cad6277e3a
Added waterway.bottleneck_overview view to database schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1012
diff
changeset
|
586 objnam AS name, |
72cad6277e3a
Added waterway.bottleneck_overview view to database schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1012
diff
changeset
|
587 ST_Centroid(area)::Geometry AS point, |
72cad6277e3a
Added waterway.bottleneck_overview view to database schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1012
diff
changeset
|
588 (lower(stretch)).hectometre AS from, |
72cad6277e3a
Added waterway.bottleneck_overview view to database schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1012
diff
changeset
|
589 (upper(stretch)).hectometre AS to, |
1520
6ad1f431bc85
Fixed date of latest measurement in bottlenecks list.
Sascha Wilde <wilde@intevation.de>
parents:
1446
diff
changeset
|
590 sr.current::text |
1831
74a3d8d8939e
Remove superfluous schema qualifiers in definition of the schema itself
Tom Gottfried <tom@intevation.de>
parents:
1826
diff
changeset
|
591 FROM bottlenecks bn LEFT JOIN ( |
74a3d8d8939e
Remove superfluous schema qualifiers in definition of the schema itself
Tom Gottfried <tom@intevation.de>
parents:
1826
diff
changeset
|
592 SELECT bottleneck_id, max(date_info) AS current FROM sounding_results |
1572
056a86b24be2
Made bottleneck primary key an int. Attention: This may break something!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1547
diff
changeset
|
593 GROUP BY bottleneck_id) sr ON sr.bottleneck_id = bn.id |
1085
72cad6277e3a
Added waterway.bottleneck_overview view to database schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1012
diff
changeset
|
594 ORDER BY objnam |
1547
d4b7a6d054cd
Add table to store import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1520
diff
changeset
|
595 |
d4b7a6d054cd
Add table to store import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1520
diff
changeset
|
596 CREATE TABLE import_configuration ( |
d4b7a6d054cd
Add table to store import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1520
diff
changeset
|
597 id int PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, |
d4b7a6d054cd
Add table to store import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1520
diff
changeset
|
598 username varchar NOT NULL |
d4b7a6d054cd
Add table to store import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1520
diff
changeset
|
599 REFERENCES internal.user_profiles(username) |
d4b7a6d054cd
Add table to store import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1520
diff
changeset
|
600 ON DELETE CASCADE |
d4b7a6d054cd
Add table to store import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1520
diff
changeset
|
601 ON UPDATE CASCADE, |
d4b7a6d054cd
Add table to store import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1520
diff
changeset
|
602 kind varchar NOT NULL, |
1583
caedd9b176f2
Added GET to /api/imports/scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1572
diff
changeset
|
603 send_email boolean NOT NULL DEFAULT false, |
1547
d4b7a6d054cd
Add table to store import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1520
diff
changeset
|
604 cron varchar, |
d4b7a6d054cd
Add table to store import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1520
diff
changeset
|
605 url varchar |
d4b7a6d054cd
Add table to store import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1520
diff
changeset
|
606 ) |
1702
49b89575ab31
Import configuration: [WIP] Added table for extra configuration attributes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1684
diff
changeset
|
607 |
49b89575ab31
Import configuration: [WIP] Added table for extra configuration attributes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1684
diff
changeset
|
608 CREATE TABLE import_configuration_attributes ( |
49b89575ab31
Import configuration: [WIP] Added table for extra configuration attributes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1684
diff
changeset
|
609 import_configuration_id int NOT NULL |
49b89575ab31
Import configuration: [WIP] Added table for extra configuration attributes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1684
diff
changeset
|
610 REFERENCES import_configuration(id) |
49b89575ab31
Import configuration: [WIP] Added table for extra configuration attributes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1684
diff
changeset
|
611 ON DELETE CASCADE |
49b89575ab31
Import configuration: [WIP] Added table for extra configuration attributes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1684
diff
changeset
|
612 ON UPDATE CASCADE, |
49b89575ab31
Import configuration: [WIP] Added table for extra configuration attributes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1684
diff
changeset
|
613 k VARCHAR NOT NULL, |
49b89575ab31
Import configuration: [WIP] Added table for extra configuration attributes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1684
diff
changeset
|
614 v TEXT NOT NULL, |
49b89575ab31
Import configuration: [WIP] Added table for extra configuration attributes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1684
diff
changeset
|
615 UNIQUE (import_configuration_id, k) |
49b89575ab31
Import configuration: [WIP] Added table for extra configuration attributes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1684
diff
changeset
|
616 ) |
195
5dc8e734487a
Introduce database schemas as privilege-based namespaces
Tom Gottfried <tom@intevation.de>
parents:
184
diff
changeset
|
617 ; |
56
f378959820be
Started to draft schema for fairway availability.
Tom Gottfried <tom@intevation.de>
parents:
55
diff
changeset
|
618 |
1446
1e19184472bf
Add configuration of primary key metadata used by geoserver.
Sascha Wilde <wilde@intevation.de>
parents:
1392
diff
changeset
|
619 -- Configure primary keys for geoserver views |
1e19184472bf
Add configuration of primary key metadata used by geoserver.
Sascha Wilde <wilde@intevation.de>
parents:
1392
diff
changeset
|
620 INSERT INTO waterway.gt_pk_metadata VALUES ('waterway', |
1e19184472bf
Add configuration of primary key metadata used by geoserver.
Sascha Wilde <wilde@intevation.de>
parents:
1392
diff
changeset
|
621 'distance_marks_geoserver', |
1e19184472bf
Add configuration of primary key metadata used by geoserver.
Sascha Wilde <wilde@intevation.de>
parents:
1392
diff
changeset
|
622 'location_code'); |
1e19184472bf
Add configuration of primary key metadata used by geoserver.
Sascha Wilde <wilde@intevation.de>
parents:
1392
diff
changeset
|
623 |
1e19184472bf
Add configuration of primary key metadata used by geoserver.
Sascha Wilde <wilde@intevation.de>
parents:
1392
diff
changeset
|
624 |
1012
875b0a9a3c92
Fixed schema definition of import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
998
diff
changeset
|
625 -- |
875b0a9a3c92
Fixed schema definition of import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
998
diff
changeset
|
626 -- Import queue and respective logging |
875b0a9a3c92
Fixed schema definition of import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
998
diff
changeset
|
627 -- |
1190
e3de65179889
The imort queue has now six states:
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1172
diff
changeset
|
628 CREATE TYPE waterway.import_state AS ENUM ( |
1975
d966f03ea819
Imports: Added the new state 'unchanged' which can be issued by the imports to indicate that the database is not modified by the particular imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1963
diff
changeset
|
629 'queued', |
d966f03ea819
Imports: Added the new state 'unchanged' which can be issued by the imports to indicate that the database is not modified by the particular imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1963
diff
changeset
|
630 'running', |
d966f03ea819
Imports: Added the new state 'unchanged' which can be issued by the imports to indicate that the database is not modified by the particular imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1963
diff
changeset
|
631 'failed', 'unchanged', 'pending', |
d966f03ea819
Imports: Added the new state 'unchanged' which can be issued by the imports to indicate that the database is not modified by the particular imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1963
diff
changeset
|
632 'accepted', 'declined' |
1190
e3de65179889
The imort queue has now six states:
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1172
diff
changeset
|
633 ); |
1012
875b0a9a3c92
Fixed schema definition of import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
998
diff
changeset
|
634 |
875b0a9a3c92
Fixed schema definition of import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
998
diff
changeset
|
635 CREATE TABLE waterway.imports ( |
1708
49e047c2106e
Imports: Made imports re-runnable if they fail.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1702
diff
changeset
|
636 id int PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, |
49e047c2106e
Imports: Made imports re-runnable if they fail.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1702
diff
changeset
|
637 state waterway.import_state NOT NULL DEFAULT 'queued', |
49e047c2106e
Imports: Made imports re-runnable if they fail.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1702
diff
changeset
|
638 kind varchar NOT NULL, |
49e047c2106e
Imports: Made imports re-runnable if they fail.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1702
diff
changeset
|
639 enqueued timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, |
49e047c2106e
Imports: Made imports re-runnable if they fail.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1702
diff
changeset
|
640 due timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, |
49e047c2106e
Imports: Made imports re-runnable if they fail.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1702
diff
changeset
|
641 trys_left int, |
49e047c2106e
Imports: Made imports re-runnable if they fail.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1702
diff
changeset
|
642 username varchar NOT NULL |
1012
875b0a9a3c92
Fixed schema definition of import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
998
diff
changeset
|
643 REFERENCES internal.user_profiles(username) |
1194
7db850de0952
Added a signer who makes the final decison on an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1193
diff
changeset
|
644 ON DELETE CASCADE |
7db850de0952
Added a signer who makes the final decison on an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1193
diff
changeset
|
645 ON UPDATE CASCADE, |
7db850de0952
Added a signer who makes the final decison on an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1193
diff
changeset
|
646 signer varchar |
7db850de0952
Added a signer who makes the final decison on an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1193
diff
changeset
|
647 REFERENCES internal.user_profiles(username) |
7db850de0952
Added a signer who makes the final decison on an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1193
diff
changeset
|
648 ON DELETE SET NULL |
7db850de0952
Added a signer who makes the final decison on an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1193
diff
changeset
|
649 ON UPDATE CASCADE, |
1759
0edebe44067d
Import queue: Removed auto_accept from imports table, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1754
diff
changeset
|
650 send_email boolean NOT NULL DEFAULT false, |
0edebe44067d
Import queue: Removed auto_accept from imports table, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1754
diff
changeset
|
651 data TEXT, |
0edebe44067d
Import queue: Removed auto_accept from imports table, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1754
diff
changeset
|
652 summary TEXT |
1012
875b0a9a3c92
Fixed schema definition of import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
998
diff
changeset
|
653 ); |
875b0a9a3c92
Fixed schema definition of import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
998
diff
changeset
|
654 |
875b0a9a3c92
Fixed schema definition of import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
998
diff
changeset
|
655 CREATE INDEX enqueued_idx ON waterway.imports(enqueued, state); |
875b0a9a3c92
Fixed schema definition of import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
998
diff
changeset
|
656 |
875b0a9a3c92
Fixed schema definition of import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
998
diff
changeset
|
657 CREATE TYPE waterway.log_type AS ENUM ('info', 'warn', 'error'); |
875b0a9a3c92
Fixed schema definition of import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
998
diff
changeset
|
658 |
875b0a9a3c92
Fixed schema definition of import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
998
diff
changeset
|
659 CREATE TABLE waterway.import_logs ( |
1172
c3955e3db074
Propagate deletion of imports through the track_imports table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1168
diff
changeset
|
660 import_id int NOT NULL REFERENCES waterway.imports(id) ON DELETE CASCADE, |
1012
875b0a9a3c92
Fixed schema definition of import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
998
diff
changeset
|
661 time timestamp NOT NULL DEFAULT now(), |
875b0a9a3c92
Fixed schema definition of import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
998
diff
changeset
|
662 kind waterway.log_type NOT NULL DEFAULT 'info', |
875b0a9a3c92
Fixed schema definition of import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
998
diff
changeset
|
663 msg TEXT NOT NULL |
875b0a9a3c92
Fixed schema definition of import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
998
diff
changeset
|
664 ); |
875b0a9a3c92
Fixed schema definition of import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
998
diff
changeset
|
665 |
1168
930fdd8b474f
Track successfull imports in a separate table to be able to remove them later.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1133
diff
changeset
|
666 CREATE TABLE waterway.track_imports ( |
1172
c3955e3db074
Propagate deletion of imports through the track_imports table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1168
diff
changeset
|
667 import_id int NOT NULL REFERENCES waterway.imports(id) ON DELETE CASCADE, |
1168
930fdd8b474f
Track successfull imports in a separate table to be able to remove them later.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1133
diff
changeset
|
668 relation regclass NOT NULL, |
930fdd8b474f
Track successfull imports in a separate table to be able to remove them later.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1133
diff
changeset
|
669 key int NOT NULL, |
930fdd8b474f
Track successfull imports in a separate table to be able to remove them later.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1133
diff
changeset
|
670 UNIQUE (relation, key) |
930fdd8b474f
Track successfull imports in a separate table to be able to remove them later.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1133
diff
changeset
|
671 ); |
930fdd8b474f
Track successfull imports in a separate table to be able to remove them later.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1133
diff
changeset
|
672 |
1193
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1190
diff
changeset
|
673 CREATE FUNCTION waterway.del_import(imp_id int) RETURNS void AS |
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1190
diff
changeset
|
674 $$ |
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1190
diff
changeset
|
675 DECLARE |
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1190
diff
changeset
|
676 tmp RECORD; |
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1190
diff
changeset
|
677 BEGIN |
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1190
diff
changeset
|
678 FOR tmp IN |
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1190
diff
changeset
|
679 SELECT * FROM waterway.track_imports WHERE import_id = imp_id |
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1190
diff
changeset
|
680 LOOP |
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1190
diff
changeset
|
681 EXECUTE format('DELETE FROM %s WHERE id = $1', tmp.relation) USING tmp.key; |
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1190
diff
changeset
|
682 END LOOP; |
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1190
diff
changeset
|
683 END; |
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1190
diff
changeset
|
684 $$ |
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1190
diff
changeset
|
685 LANGUAGE plpgsql; |
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1190
diff
changeset
|
686 |
1172
c3955e3db074
Propagate deletion of imports through the track_imports table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1168
diff
changeset
|
687 CREATE FUNCTION waterway.del_import() RETURNS trigger AS |
c3955e3db074
Propagate deletion of imports through the track_imports table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1168
diff
changeset
|
688 $$ |
c3955e3db074
Propagate deletion of imports through the track_imports table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1168
diff
changeset
|
689 BEGIN |
1193
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1190
diff
changeset
|
690 EXECUTE format('DELETE FROM %s WHERE id = $1', OLD.relation) USING OLD.key; |
1354
1000e0e71d5a
Added missing rights and fixed trigger function.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1338
diff
changeset
|
691 RETURN NULL; |
1172
c3955e3db074
Propagate deletion of imports through the track_imports table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1168
diff
changeset
|
692 END; |
c3955e3db074
Propagate deletion of imports through the track_imports table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1168
diff
changeset
|
693 $$ |
c3955e3db074
Propagate deletion of imports through the track_imports table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1168
diff
changeset
|
694 LANGUAGE plpgsql; |
c3955e3db074
Propagate deletion of imports through the track_imports table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1168
diff
changeset
|
695 |
35
62e14b4d25fc
First working draft of schema for bottlenecks.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
696 COMMIT; |