From: malexander <malexander@catalyte.io>
Date: Wed, 8 Dec 2021 19:12:23 +0000 (+0000)
Subject: lp-1942645 term name uniqueness
X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=90833952b2e590564c52c55232825059b00fd11b;p=Evergreen.git

lp-1942645 term name uniqueness

dropped name uniqueness between orgs, added constraint to owning lib and name

Includes syntax corrections from Martha Driscoll -- thank you, Martha!

Signed-off-by: malexander <malexander@catalyte.io>
Signed-off-by: Beth Willis <willis@noblenet.org>
Signed-off-by: Jane Sandberg <sandbergja@gmail.com>
---

diff --git a/Open-ILS/src/sql/Pg/040.schema.asset.sql b/Open-ILS/src/sql/Pg/040.schema.asset.sql
index f1455306f5..507ea3ad04 100644
--- a/Open-ILS/src/sql/Pg/040.schema.asset.sql
+++ b/Open-ILS/src/sql/Pg/040.schema.asset.sql
@@ -1145,10 +1145,11 @@ CREATE TABLE asset.course_module_course_materials (
 
 CREATE TABLE asset.course_module_term (
     id              SERIAL  PRIMARY KEY,
-    name            TEXT    UNIQUE NOT NULL,
+    name            TEXT NOT NULL,
     owning_lib      INT REFERENCES actor.org_unit (id),
 	start_date      TIMESTAMP WITH TIME ZONE,
-	end_date        TIMESTAMP WITH TIME ZONE
+	end_date        TIMESTAMP WITH TIME ZONE,
+    CONSTRAINT cmt_once_per_owning_lib UNIQUE (owning_lib, name)
 );
 
 CREATE TABLE asset.course_module_term_course_map (
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.update_course_module_term_constraints.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.update_course_module_term_constraints.sql
new file mode 100644
index 0000000000..e4cbfe7b15
--- /dev/null
+++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.update_course_module_term_constraints.sql
@@ -0,0 +1,11 @@
+BEGIN;
+
+SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
+
+ALTER TABLE asset.course_module_term
+        DROP CONSTRAINT course_module_term_name_key;
+
+ALTER TABLE asset.course_module_term
+        ADD CONSTRAINT cmt_once_per_owning_lib UNIQUE (owning_lib, name);
+
+COMMIT;