Mercurial > lada > lada-server
comparison db_schema/lada_schema.sql @ 999:813461e9a7be schema-update
Reordered table creation to allow inline definition of FKs.
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Fri, 01 Jul 2016 18:17:23 +0200 |
parents | c22a99d5c6f1 |
children | 1489f0ade850 |
comparison
equal
deleted
inserted
replaced
998:c22a99d5c6f1 | 999:813461e9a7be |
---|---|
159 START WITH 1 | 159 START WITH 1 |
160 INCREMENT BY 1 | 160 INCREMENT BY 1 |
161 NO MINVALUE | 161 NO MINVALUE |
162 NO MAXVALUE | 162 NO MAXVALUE |
163 CACHE 1; | 163 CACHE 1; |
164 | |
165 | |
166 -- | |
167 -- Name: kommentar_m; Type: TABLE; Schema: land; Owner: -; Tablespace: | |
168 -- | |
169 | |
170 CREATE TABLE kommentar_m ( | |
171 id serial PRIMARY KEY, | |
172 erzeuger character varying(5) NOT NULL, | |
173 datum timestamp without time zone DEFAULT now(), | |
174 text character varying(1024), | |
175 messungs_id integer NOT NULL | |
176 ); | |
177 | |
178 | |
179 -- | |
180 -- Name: kommentar_p; Type: TABLE; Schema: land; Owner: -; Tablespace: | |
181 -- | |
182 | |
183 CREATE TABLE kommentar_p ( | |
184 id serial PRIMARY KEY, | |
185 erzeuger character varying(5) NOT NULL, | |
186 datum timestamp without time zone DEFAULT now(), | |
187 text character varying(1024), | |
188 probe_id integer NOT NULL | |
189 ); | |
190 | 164 |
191 | 165 |
192 -- | 166 -- |
193 -- Name: messprogramm; Type: TABLE; Schema: land; Owner: -; Tablespace: | 167 -- Name: messprogramm; Type: TABLE; Schema: land; Owner: -; Tablespace: |
194 -- | 168 -- |
239 mmt_id character varying(2) NOT NULL, | 213 mmt_id character varying(2) NOT NULL, |
240 messgroessen integer[], | 214 messgroessen integer[], |
241 letzte_aenderung timestamp without time zone DEFAULT now() | 215 letzte_aenderung timestamp without time zone DEFAULT now() |
242 ); | 216 ); |
243 CREATE TRIGGER letzte_aenderung_messprogramm_mmt BEFORE UPDATE ON messprogramm_mmt FOR EACH ROW EXECUTE PROCEDURE update_letzte_aenderung(); | 217 CREATE TRIGGER letzte_aenderung_messprogramm_mmt BEFORE UPDATE ON messprogramm_mmt FOR EACH ROW EXECUTE PROCEDURE update_letzte_aenderung(); |
244 | |
245 | |
246 -- | |
247 -- Name: messung; Type: TABLE; Schema: land; Owner: -; Tablespace: | |
248 -- | |
249 | |
250 CREATE TABLE messung ( | |
251 id serial PRIMARY KEY, | |
252 id_alt integer DEFAULT nextval('land.messung_messung_id_alt_seq'::regclass) NOT NULL, | |
253 probe_id integer NOT NULL, | |
254 nebenproben_nr character varying(10), | |
255 mmt_id character varying(2) NOT NULL, | |
256 messdauer integer, | |
257 messzeitpunkt timestamp with time zone, | |
258 fertig boolean DEFAULT false NOT NULL, | |
259 status integer, | |
260 letzte_aenderung timestamp without time zone DEFAULT now(), | |
261 geplant boolean DEFAULT false NOT NULL, | |
262 tree_modified timestamp without time zone DEFAULT now() | |
263 ); | |
264 | |
265 | |
266 -- | |
267 -- Name: messwert; Type: TABLE; Schema: land; Owner: -; Tablespace: | |
268 -- | |
269 | |
270 CREATE TABLE messwert ( | |
271 id serial PRIMARY KEY, | |
272 messungs_id integer NOT NULL, | |
273 messgroesse_id integer NOT NULL, | |
274 messwert_nwg character varying(1), | |
275 messwert double precision NOT NULL, | |
276 messfehler real, | |
277 nwg_zu_messwert double precision, | |
278 meh_id smallint NOT NULL, | |
279 grenzwertueberschreitung boolean DEFAULT false, | |
280 letzte_aenderung timestamp without time zone DEFAULT now(), | |
281 tree_modified timestamp without time zone DEFAULT now(), | |
282 UNIQUE (messungs_id, messgroesse_id) | |
283 ); | |
284 CREATE TRIGGER letzte_aenderung_messwert BEFORE UPDATE ON messwert FOR EACH ROW EXECUTE PROCEDURE update_letzte_aenderung(); | |
285 | |
286 | |
287 -- | |
288 -- Name: ortszuordnung; Type: TABLE; Schema: land; Owner: -; Tablespace: | |
289 -- | |
290 | |
291 CREATE TABLE ortszuordnung ( | |
292 id serial PRIMARY KEY, | |
293 probe_id integer NOT NULL, | |
294 ort_id bigint NOT NULL, | |
295 ortszuordnung_typ character varying(1), | |
296 ortszusatztext character varying(100), | |
297 letzte_aenderung timestamp without time zone DEFAULT now(), | |
298 tree_modified timestamp without time zone DEFAULT now() | |
299 ); | |
300 CREATE TRIGGER letzte_aenderung_ortszuordnung BEFORE UPDATE ON ortszuordnung FOR EACH ROW EXECUTE PROCEDURE update_letzte_aenderung(); | |
301 | |
302 -- | |
303 -- Name: COLUMN ortszuordnung.ortszuordnung_typ; Type: COMMENT; Schema: land; Owner: - | |
304 -- | |
305 | |
306 COMMENT ON COLUMN ortszuordnung.ortszuordnung_typ IS 'E = Entnahmeport, U = Ursprungsort, Z = Ortszusatz'; | |
307 | 218 |
308 | 219 |
309 -- | 220 -- |
310 -- Name: probe; Type: TABLE; Schema: land; Owner: -; Tablespace: | 221 -- Name: probe; Type: TABLE; Schema: land; Owner: -; Tablespace: |
311 -- | 222 -- |
340 tree_modified timestamp without time zone DEFAULT now(), | 251 tree_modified timestamp without time zone DEFAULT now(), |
341 UNIQUE (mst_id, hauptproben_nr) | 252 UNIQUE (mst_id, hauptproben_nr) |
342 ); | 253 ); |
343 CREATE TRIGGER letzte_aenderung_probe BEFORE UPDATE ON probe FOR EACH ROW EXECUTE PROCEDURE update_letzte_aenderung(); | 254 CREATE TRIGGER letzte_aenderung_probe BEFORE UPDATE ON probe FOR EACH ROW EXECUTE PROCEDURE update_letzte_aenderung(); |
344 | 255 |
345 -- | 256 |
346 -- Name: COLUMN probe.id; Type: COMMENT; Schema: land; Owner: - | 257 -- |
347 -- | 258 -- Name: kommentar_p; Type: TABLE; Schema: land; Owner: -; Tablespace: |
348 | 259 -- |
349 COMMENT ON COLUMN probe.id IS 'interner Probenschlüssel'; | 260 |
350 | 261 CREATE TABLE kommentar_p ( |
351 | |
352 -- | |
353 -- Name: COLUMN probe.test; Type: COMMENT; Schema: land; Owner: - | |
354 -- | |
355 | |
356 COMMENT ON COLUMN probe.test IS 'Ist Testdatensatz?'; | |
357 | |
358 | |
359 -- | |
360 -- Name: COLUMN probe.mst_id; Type: COMMENT; Schema: land; Owner: - | |
361 -- | |
362 | |
363 COMMENT ON COLUMN probe.mst_id IS 'ID für Messstelle'; | |
364 | |
365 | |
366 -- | |
367 -- Name: COLUMN probe.labor_mst_id; Type: COMMENT; Schema: land; Owner: - | |
368 -- | |
369 | |
370 COMMENT ON COLUMN probe.labor_mst_id IS '-- ID für Messlabor'; | |
371 | |
372 | |
373 -- | |
374 -- Name: COLUMN probe.hauptproben_nr; Type: COMMENT; Schema: land; Owner: - | |
375 -- | |
376 | |
377 COMMENT ON COLUMN probe.hauptproben_nr IS 'externer Probensclüssel'; | |
378 | |
379 | |
380 -- | |
381 -- Name: COLUMN probe.ba_id; Type: COMMENT; Schema: land; Owner: - | |
382 -- | |
383 | |
384 COMMENT ON COLUMN probe.ba_id IS 'ID der Betriebsart (normal/Routine oder Störfall/intensiv)'; | |
385 | |
386 | |
387 -- | |
388 -- Name: COLUMN probe.probenart_id; Type: COMMENT; Schema: land; Owner: - | |
389 -- | |
390 | |
391 COMMENT ON COLUMN probe.probenart_id IS 'ID der Probenart(Einzel-, Sammel-, Misch- ...Probe)'; | |
392 | |
393 | |
394 -- | |
395 -- Name: COLUMN probe.media_desk; Type: COMMENT; Schema: land; Owner: - | |
396 -- | |
397 | |
398 COMMENT ON COLUMN probe.media_desk IS 'Mediencodierung (Deskriptoren oder ADV-Codierung)'; | |
399 | |
400 | |
401 -- | |
402 -- Name: COLUMN probe.media; Type: COMMENT; Schema: land; Owner: - | |
403 -- | |
404 | |
405 COMMENT ON COLUMN probe.media IS 'dekodierte Medienbezeichnung (aus media_desk abgeleitet)'; | |
406 | |
407 | |
408 -- | |
409 -- Name: COLUMN probe.umw_id; Type: COMMENT; Schema: land; Owner: - | |
410 -- | |
411 | |
412 COMMENT ON COLUMN probe.umw_id IS 'ID für Umweltbereich'; | |
413 | |
414 | |
415 -- | |
416 -- Name: status_protokoll; Type: TABLE; Schema: land; Owner: -; Tablespace: | |
417 -- | |
418 | |
419 CREATE TABLE status_protokoll ( | |
420 id serial PRIMARY KEY, | 262 id serial PRIMARY KEY, |
421 erzeuger character varying(5) NOT NULL, | 263 erzeuger character varying(5) NOT NULL, |
422 datum timestamp without time zone DEFAULT now(), | 264 datum timestamp without time zone DEFAULT now(), |
423 text character varying(1024), | 265 text character varying(1024), |
424 messungs_id integer NOT NULL, | 266 probe_id integer NOT NULL |
425 status_stufe integer NOT NULL, | 267 ); |
426 status_wert integer NOT NULL, | 268 |
269 | |
270 -- | |
271 -- Name: ortszuordnung; Type: TABLE; Schema: land; Owner: -; Tablespace: | |
272 -- | |
273 | |
274 CREATE TABLE ortszuordnung ( | |
275 id serial PRIMARY KEY, | |
276 probe_id integer NOT NULL, | |
277 ort_id bigint NOT NULL, | |
278 ortszuordnung_typ character varying(1), | |
279 ortszusatztext character varying(100), | |
280 letzte_aenderung timestamp without time zone DEFAULT now(), | |
427 tree_modified timestamp without time zone DEFAULT now() | 281 tree_modified timestamp without time zone DEFAULT now() |
428 ); | 282 ); |
283 CREATE TRIGGER letzte_aenderung_ortszuordnung BEFORE UPDATE ON ortszuordnung FOR EACH ROW EXECUTE PROCEDURE update_letzte_aenderung(); | |
429 | 284 |
430 | 285 |
431 -- | 286 -- |
432 -- Name: zusatz_wert; Type: TABLE; Schema: land; Owner: -; Tablespace: | 287 -- Name: zusatz_wert; Type: TABLE; Schema: land; Owner: -; Tablespace: |
433 -- | 288 -- |
445 ); | 300 ); |
446 CREATE TRIGGER letzte_aenderung_zusatzwert BEFORE UPDATE ON zusatz_wert FOR EACH ROW EXECUTE PROCEDURE update_letzte_aenderung(); | 301 CREATE TRIGGER letzte_aenderung_zusatzwert BEFORE UPDATE ON zusatz_wert FOR EACH ROW EXECUTE PROCEDURE update_letzte_aenderung(); |
447 | 302 |
448 | 303 |
449 -- | 304 -- |
305 -- Name: COLUMN ortszuordnung.ortszuordnung_typ; Type: COMMENT; Schema: land; Owner: - | |
306 -- | |
307 | |
308 COMMENT ON COLUMN ortszuordnung.ortszuordnung_typ IS 'E = Entnahmeport, U = Ursprungsort, Z = Ortszusatz'; | |
309 | |
310 | |
311 -- | |
312 -- Name: COLUMN probe.id; Type: COMMENT; Schema: land; Owner: - | |
313 -- | |
314 | |
315 COMMENT ON COLUMN probe.id IS 'interner Probenschlüssel'; | |
316 | |
317 | |
318 -- | |
319 -- Name: COLUMN probe.test; Type: COMMENT; Schema: land; Owner: - | |
320 -- | |
321 | |
322 COMMENT ON COLUMN probe.test IS 'Ist Testdatensatz?'; | |
323 | |
324 | |
325 -- | |
326 -- Name: COLUMN probe.mst_id; Type: COMMENT; Schema: land; Owner: - | |
327 -- | |
328 | |
329 COMMENT ON COLUMN probe.mst_id IS 'ID für Messstelle'; | |
330 | |
331 | |
332 -- | |
333 -- Name: COLUMN probe.labor_mst_id; Type: COMMENT; Schema: land; Owner: - | |
334 -- | |
335 | |
336 COMMENT ON COLUMN probe.labor_mst_id IS '-- ID für Messlabor'; | |
337 | |
338 | |
339 -- | |
340 -- Name: COLUMN probe.hauptproben_nr; Type: COMMENT; Schema: land; Owner: - | |
341 -- | |
342 | |
343 COMMENT ON COLUMN probe.hauptproben_nr IS 'externer Probensclüssel'; | |
344 | |
345 | |
346 -- | |
347 -- Name: COLUMN probe.ba_id; Type: COMMENT; Schema: land; Owner: - | |
348 -- | |
349 | |
350 COMMENT ON COLUMN probe.ba_id IS 'ID der Betriebsart (normal/Routine oder Störfall/intensiv)'; | |
351 | |
352 | |
353 -- | |
354 -- Name: COLUMN probe.probenart_id; Type: COMMENT; Schema: land; Owner: - | |
355 -- | |
356 | |
357 COMMENT ON COLUMN probe.probenart_id IS 'ID der Probenart(Einzel-, Sammel-, Misch- ...Probe)'; | |
358 | |
359 | |
360 -- | |
361 -- Name: COLUMN probe.media_desk; Type: COMMENT; Schema: land; Owner: - | |
362 -- | |
363 | |
364 COMMENT ON COLUMN probe.media_desk IS 'Mediencodierung (Deskriptoren oder ADV-Codierung)'; | |
365 | |
366 | |
367 -- | |
368 -- Name: COLUMN probe.media; Type: COMMENT; Schema: land; Owner: - | |
369 -- | |
370 | |
371 COMMENT ON COLUMN probe.media IS 'dekodierte Medienbezeichnung (aus media_desk abgeleitet)'; | |
372 | |
373 | |
374 -- | |
375 -- Name: COLUMN probe.umw_id; Type: COMMENT; Schema: land; Owner: - | |
376 -- | |
377 | |
378 COMMENT ON COLUMN probe.umw_id IS 'ID für Umweltbereich'; | |
379 | |
380 | |
381 -- | |
382 -- Name: messung; Type: TABLE; Schema: land; Owner: -; Tablespace: | |
383 -- | |
384 | |
385 CREATE TABLE messung ( | |
386 id serial PRIMARY KEY, | |
387 id_alt integer DEFAULT nextval('land.messung_messung_id_alt_seq'::regclass) NOT NULL, | |
388 probe_id integer NOT NULL, | |
389 nebenproben_nr character varying(10), | |
390 mmt_id character varying(2) NOT NULL, | |
391 messdauer integer, | |
392 messzeitpunkt timestamp with time zone, | |
393 fertig boolean DEFAULT false NOT NULL, | |
394 status integer, | |
395 letzte_aenderung timestamp without time zone DEFAULT now(), | |
396 geplant boolean DEFAULT false NOT NULL, | |
397 tree_modified timestamp without time zone DEFAULT now() | |
398 ); | |
399 | |
400 | |
401 -- | |
402 -- Name: kommentar_m; Type: TABLE; Schema: land; Owner: -; Tablespace: | |
403 -- | |
404 | |
405 CREATE TABLE kommentar_m ( | |
406 id serial PRIMARY KEY, | |
407 erzeuger character varying(5) NOT NULL, | |
408 datum timestamp without time zone DEFAULT now(), | |
409 text character varying(1024), | |
410 messungs_id integer NOT NULL | |
411 ); | |
412 | |
413 | |
414 -- | |
415 -- Name: messwert; Type: TABLE; Schema: land; Owner: -; Tablespace: | |
416 -- | |
417 | |
418 CREATE TABLE messwert ( | |
419 id serial PRIMARY KEY, | |
420 messungs_id integer NOT NULL, | |
421 messgroesse_id integer NOT NULL, | |
422 messwert_nwg character varying(1), | |
423 messwert double precision NOT NULL, | |
424 messfehler real, | |
425 nwg_zu_messwert double precision, | |
426 meh_id smallint NOT NULL, | |
427 grenzwertueberschreitung boolean DEFAULT false, | |
428 letzte_aenderung timestamp without time zone DEFAULT now(), | |
429 tree_modified timestamp without time zone DEFAULT now(), | |
430 UNIQUE (messungs_id, messgroesse_id) | |
431 ); | |
432 CREATE TRIGGER letzte_aenderung_messwert BEFORE UPDATE ON messwert FOR EACH ROW EXECUTE PROCEDURE update_letzte_aenderung(); | |
433 | |
434 | |
435 -- | |
436 -- Name: status_protokoll; Type: TABLE; Schema: land; Owner: -; Tablespace: | |
437 -- | |
438 | |
439 CREATE TABLE status_protokoll ( | |
440 id serial PRIMARY KEY, | |
441 erzeuger character varying(5) NOT NULL, | |
442 datum timestamp without time zone DEFAULT now(), | |
443 text character varying(1024), | |
444 messungs_id integer NOT NULL, | |
445 status_stufe integer NOT NULL, | |
446 status_wert integer NOT NULL, | |
447 tree_modified timestamp without time zone DEFAULT now() | |
448 ); | |
449 | |
450 | |
451 -- | |
450 -- Name: messung_probe_id_idx; Type: INDEX; Schema: land; Owner: -; Tablespace: | 452 -- Name: messung_probe_id_idx; Type: INDEX; Schema: land; Owner: -; Tablespace: |
451 -- | 453 -- |
452 | 454 |
453 CREATE INDEX messung_probe_id_idx ON messung USING btree (probe_id); | 455 CREATE INDEX messung_probe_id_idx ON messung USING btree (probe_id); |
454 | 456 |