lp-1942645 term name uniqueness
authormalexander <malexander@catalyte.io>
Wed, 8 Dec 2021 19:12:23 +0000 (19:12 +0000)
committerJane Sandberg <sandbergja@gmail.com>
Tue, 14 Dec 2021 20:52:54 +0000 (12:52 -0800)
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>
Open-ILS/src/sql/Pg/040.schema.asset.sql
Open-ILS/src/sql/Pg/upgrade/XXXX.schema.update_course_module_term_constraints.sql [new file with mode: 0644]

index 44de65b..e269238 100644 (file)
@@ -1132,10 +1132,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 (file)
index 0000000..e4cbfe7
--- /dev/null
@@ -0,0 +1,11 @@
+BEGIN;\r
+\r
+SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);\r
+\r
+ALTER TABLE asset.course_module_term\r
+        DROP CONSTRAINT course_module_term_name_key;\r
+\r
+ALTER TABLE asset.course_module_term\r
+        ADD CONSTRAINT cmt_once_per_owning_lib UNIQUE (owning_lib, name);\r
+\r
+COMMIT;\r