From 61b77b2db2183e34ba09442c878c9a2913d624be Mon Sep 17 00:00:00 2001
From: scottmk <scottmk@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Date: Mon, 15 Feb 2010 15:12:14 +0000
Subject: [PATCH] In acq.lineitem_alert_text: add owning_lib column.  Also make
 the UNIQUE constraint apply to code + owning_lib, not just code.

M    Open-ILS/src/sql/Pg/200.schema.acq.sql
M    Open-ILS/src/sql/Pg/002.schema.config.sql
A    Open-ILS/src/sql/Pg/upgrade/0161.schema.acq.alert-text-org.sql
M    Open-ILS/examples/fm_IDL.xml


git-svn-id: svn://svn.open-ils.org/ILS/trunk@15533 dcc99617-32d9-48b4-a31d-7c20da2025e4
---
 Open-ILS/examples/fm_IDL.xml                             |  2 ++
 Open-ILS/src/sql/Pg/002.schema.config.sql                |  2 +-
 Open-ILS/src/sql/Pg/200.schema.acq.sql                   |  8 ++++++--
 .../sql/Pg/upgrade/0161.schema.acq.alert-text-org.sql    | 16 ++++++++++++++++
 4 files changed, 25 insertions(+), 3 deletions(-)
 create mode 100644 Open-ILS/src/sql/Pg/upgrade/0161.schema.acq.alert-text-org.sql

diff --git a/Open-ILS/examples/fm_IDL.xml b/Open-ILS/examples/fm_IDL.xml
index ca211a8fcd..f9b1ae359c 100644
--- a/Open-ILS/examples/fm_IDL.xml
+++ b/Open-ILS/examples/fm_IDL.xml
@@ -5039,8 +5039,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 			<field reporter:label="Alert Text ID" name="id" reporter:datatype="id"/>
 			<field reporter:label="Code" name="code" reporter:datatype="text"/>
 			<field reporter:label="Description" name="description" reporter:datatype="text"/>
+			<field reporter:label="Owning Library" name="owning_lib" reporter:datatype="link"/>
 		</fields>
 		<links>
+			<link field="owning_lib" reltype="has_a" key="id" map="" class="aou"/>
 		</links>
 		<permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
 		</permacrud>
diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql
index 3136273b8b..fb3dffedb3 100644
--- a/Open-ILS/src/sql/Pg/002.schema.config.sql
+++ b/Open-ILS/src/sql/Pg/002.schema.config.sql
@@ -51,7 +51,7 @@ CREATE TABLE config.upgrade_log (
     install_date    TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
 );
 
-INSERT INTO config.upgrade_log (version) VALUES ('0160'); --Scott McKellar
+INSERT INTO config.upgrade_log (version) VALUES ('0161'); --Scott McKellar
 
 CREATE TABLE config.bib_source (
 	id		SERIAL	PRIMARY KEY,
diff --git a/Open-ILS/src/sql/Pg/200.schema.acq.sql b/Open-ILS/src/sql/Pg/200.schema.acq.sql
index b75bb3794d..b1ce462e9c 100644
--- a/Open-ILS/src/sql/Pg/200.schema.acq.sql
+++ b/Open-ILS/src/sql/Pg/200.schema.acq.sql
@@ -423,8 +423,12 @@ CREATE INDEX li_selector_idx  ON acq.lineitem ( selector );
 
 CREATE TABLE acq.lineitem_alert_text (
     id               SERIAL         PRIMARY KEY,
-    code             TEXT           UNIQUE NOT NULL,
-    description      TEXT
+    code             TEXT           NOT NULL,
+    description      TEXT,
+	owning lib       INT            NOT NULL
+	                                REFERENCES actor.org_unit(id)
+	                                DEFERRABLE INITIALLY DEFERRED,
+	CONSTRAINT alert_one_code_per_org UNIQUE (code, owning_lib)
 );
 
 CREATE TABLE acq.lineitem_note (
diff --git a/Open-ILS/src/sql/Pg/upgrade/0161.schema.acq.alert-text-org.sql b/Open-ILS/src/sql/Pg/upgrade/0161.schema.acq.alert-text-org.sql
new file mode 100644
index 0000000000..ba2200f027
--- /dev/null
+++ b/Open-ILS/src/sql/Pg/upgrade/0161.schema.acq.alert-text-org.sql
@@ -0,0 +1,16 @@
+BEGIN;
+
+INSERT INTO config.upgrade_log (version) VALUES ('0161'); -- Scott McKellar
+
+ALTER TABLE acq.lineitem_alert_text
+	ADD COLUMN owning_lib INT NOT NULL
+	                          REFERENCES actor.org_unit(id)
+	                          DEFERRABLE INITIALLY DEFERRED;
+
+ALTER TABLE acq.lineitem_alert_text
+	DROP CONSTRAINT lineitem_alert_text_code_key;
+
+ALTER TABLE acq.lineitem_alert_text
+	ADD CONSTRAINT alert_one_code_per_org UNIQUE (code, owning_lib);
+
+COMMIT;
-- 
2.11.0