diff db_schema/stammdaten_schema.sql @ 872:e161d8f2d978

Add necessary constraints for status workflow.
author Tom Gottfried <tom@intevation.de>
date Mon, 08 Feb 2016 18:31:08 +0100
parents 53d739275c50
children ad64ef3379a8
line wrap: on
line diff
--- a/db_schema/stammdaten_schema.sql	Mon Feb 08 18:23:41 2016 +0100
+++ b/db_schema/stammdaten_schema.sql	Mon Feb 08 18:31:08 2016 +0100
@@ -98,7 +98,7 @@
 
 CREATE TABLE auth_funktion (
     id smallint PRIMARY KEY,
-    funktion character varying(40)
+    funktion character varying(40) UNIQUE NOT NULL
 );
 INSERT INTO auth_funktion VALUES (0, 'Erfasser');
 INSERT INTO auth_funktion VALUES (1, 'Status-Erfasser');
@@ -868,7 +868,7 @@
 -- Status workflow
 CREATE TABLE status_stufe (
     id integer PRIMARY KEY,
-    stufe character varying(50)
+    stufe character varying(50) UNIQUE NOT NULL
 );
 INSERT INTO status_stufe VALUES (1, 'MST');
 INSERT INTO status_stufe VALUES (2, 'LAND');
@@ -877,7 +877,7 @@
 
 CREATE TABLE status_wert (
     id integer PRIMARY KEY,
-    wert character varying(50)
+    wert character varying(50) UNIQUE NOT NULL
 );
 INSERT INTO status_wert VALUES (0, 'nicht vergeben');
 INSERT INTO status_wert VALUES (1, 'plausibel');
@@ -890,8 +890,9 @@
 
 CREATE TABLE status_kombi (
     id integer PRIMARY KEY,
-    stufe_id integer REFERENCES status_stufe,
-    wert_id integer REFERENCES status_wert
+    stufe_id integer REFERENCES status_stufe NOT NULL,
+    wert_id integer REFERENCES status_wert NOT NULL,
+    UNIQUE(stufe_id, wert_id)
 );
 -- 'zurückgesetzt' is left out here deliberately!
 INSERT INTO status_kombi VALUES (1, 1, 0);
@@ -912,8 +913,9 @@
 CREATE SEQUENCE status_reihenfolge_id_seq;
 CREATE TABLE status_reihenfolge (
     id integer PRIMARY KEY DEFAULT nextval('status_reihenfolge_id_seq'),
-    von_id integer REFERENCES status_kombi,
-    zu_id integer REFERENCES status_kombi
+    von_id integer REFERENCES status_kombi NOT NULL,
+    zu_id integer REFERENCES status_kombi NOT NULL,
+    UNIQUE(von_id, zu_id)
 );
 
 CREATE FUNCTION populate_status_reihenfolge() RETURNS void AS $$
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)