[Lada-commits] [PATCH 4 of 4] Fix UNIQUE-constraint and respective validation

Wald Commits scm-commit at wald.intevation.org
Mon Oct 31 18:10:53 CET 2016


# HG changeset patch
# User Tom Gottfried <tom at intevation.de>
# Date 1477933785 -3600
# Node ID 70b51893f15bc9a4e6afafbd7f0c5736ab78ca24
# Parent  f9328849a53c243d9f85aaa09f7abc237eb24cf3
Fix UNIQUE-constraint and respective validation.

Btw. improved readability of DEFAULT definition.

diff -r f9328849a53c -r 70b51893f15b db_schema/lada_schema.sql
--- a/db_schema/lada_schema.sql	Mon Oct 31 17:14:49 2016 +0100
+++ b/db_schema/lada_schema.sql	Mon Oct 31 18:09:45 2016 +0100
@@ -192,7 +192,10 @@
 
 CREATE TABLE probe (
     id serial PRIMARY KEY,
-    id_alt character varying(20) DEFAULT (('sss'::text || lpad(((nextval('land.probe_probe_id_seq'::regclass))::character varying)::text, 12, '0'::text)) || 'Y'::text) NOT NULL,
+    id_alt character varying(20) UNIQUE NOT NULL
+        DEFAULT 'sss'
+            || lpad(nextval('land.probe_probe_id_seq')::varchar, 12, '0')
+            || 'Y',
     test boolean DEFAULT false NOT NULL,
     mst_id character varying(5) NOT NULL REFERENCES stammdaten.mess_stelle,
     labor_mst_id character varying(5) NOT NULL REFERENCES stammdaten.mess_stelle,
@@ -214,7 +217,7 @@
     solldatum_beginn timestamp without time zone,
     solldatum_ende timestamp without time zone,
     tree_modified timestamp without time zone DEFAULT now(),
-    UNIQUE (mst_id, hauptproben_nr, id_alt),
+    UNIQUE (mst_id, hauptproben_nr),
     CHECK(solldatum_beginn <= solldatum_ende)
 );
 CREATE TRIGGER letzte_aenderung_probe BEFORE UPDATE ON probe FOR EACH ROW EXECUTE PROCEDURE update_letzte_aenderung();
diff -r f9328849a53c -r 70b51893f15b src/main/java/de/intevation/lada/validation/rules/probe/UniqueHauptprobenNr.java
--- a/src/main/java/de/intevation/lada/validation/rules/probe/UniqueHauptprobenNr.java	Mon Oct 31 17:14:49 2016 +0100
+++ b/src/main/java/de/intevation/lada/validation/rules/probe/UniqueHauptprobenNr.java	Mon Oct 31 18:09:45 2016 +0100
@@ -42,6 +42,7 @@
             repo.entityManager("land"),
             Probe.class);
         builder.and("hauptprobenNr", probe.getHauptprobenNr());
+        builder.and("mstId", probe.getMstId());
         Response response = repo.filter(builder.getQuery(), "land");
         if (!((List<Probe>)response.getData()).isEmpty()) {
             Probe found = ((List<Probe>)response.getData()).get(0);


More information about the Lada-commits mailing list