changeset 4717:9279fdb7a422

Ensure unique names of sections and stretches
author Tom Gottfried <tom@intevation.de>
date Thu, 17 Oct 2019 12:55:13 +0200
parents 310f5a5e2ea2
children 92640ae5be07
files schema/gemma.sql schema/updates/1307/01.unique_names.sql schema/version.sql
diffstat 3 files changed, 6 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/schema/gemma.sql	Thu Oct 17 12:47:17 2019 +0200
+++ b/schema/gemma.sql	Thu Oct 17 12:55:13 2019 +0200
@@ -407,7 +407,7 @@
 CREATE SCHEMA users
     CREATE TABLE stretches (
         id int PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY,
-        name varchar NOT NULL,
+        name varchar UNIQUE NOT NULL,
         stretch isrsrange NOT NULL,
         area geography(MULTIPOLYGON, 4326) NOT NULL
             CHECK(ST_IsValid(CAST(area AS geometry))),
@@ -582,7 +582,7 @@
     -- Like stretches without the countries
     CREATE TABLE sections (
         id int PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY,
-        name varchar NOT NULL,
+        name varchar UNIQUE NOT NULL,
         section isrsrange NOT NULL,
         area geography(MULTIPOLYGON, 4326) NOT NULL
             CHECK(ST_IsValid(CAST(area AS geometry))),
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/schema/updates/1307/01.unique_names.sql	Thu Oct 17 12:55:13 2019 +0200
@@ -0,0 +1,3 @@
+ALTER TABLE users.stretches ADD UNIQUE (name);
+
+ALTER TABLE waterway.sections ADD UNIQUE (name);
--- a/schema/version.sql	Thu Oct 17 12:47:17 2019 +0200
+++ b/schema/version.sql	Thu Oct 17 12:55:13 2019 +0200
@@ -1,1 +1,1 @@
-INSERT INTO gemma_schema_version(version) VALUES (1306);
+INSERT INTO gemma_schema_version(version) VALUES (1307);