[open-ils-commits] r18413 - branches/rel_1_6/Open-ILS/src/sql/Pg (miker)

svn at svn.open-ils.org svn at svn.open-ils.org
Wed Oct 20 12:43:29 EDT 2010


Author: miker
Date: 2010-10-20 12:43:26 -0400 (Wed, 20 Oct 2010)
New Revision: 18413

Modified:
   branches/rel_1_6/Open-ILS/src/sql/Pg/1.6.1-1.6.2-upgrade-db.sql
Log:
1.6.1-1.6.2 upgrade script needs to fall in line with reality, re 0442

Modified: branches/rel_1_6/Open-ILS/src/sql/Pg/1.6.1-1.6.2-upgrade-db.sql
===================================================================
--- branches/rel_1_6/Open-ILS/src/sql/Pg/1.6.1-1.6.2-upgrade-db.sql	2010-10-20 16:40:14 UTC (rev 18412)
+++ branches/rel_1_6/Open-ILS/src/sql/Pg/1.6.1-1.6.2-upgrade-db.sql	2010-10-20 16:43:26 UTC (rev 18413)
@@ -1,5 +1,50 @@
 BEGIN;
 
+CREATE TABLE config.hard_due_date (
+        id          SERIAL      PRIMARY KEY,
+        name        TEXT        NOT NULL UNIQUE CHECK ( name ~ E'^\\w+$' ),
+        ceiling_date    TIMESTAMPTZ NOT NULL,
+        forceto     BOOL        NOT NULL,
+        owner       INT         NOT NULL
+);
+
+CREATE TABLE config.hard_due_date_values (
+    id                  SERIAL      PRIMARY KEY,
+    hard_due_date       INT         NOT NULL REFERENCES config.hard_due_date (id)
+                                    DEFERRABLE INITIALLY DEFERRED,
+    ceiling_date        TIMESTAMPTZ NOT NULL,
+    active_date         TIMESTAMPTZ NOT NULL
+);
+
+ALTER TABLE config.circ_matrix_matchpoint ADD COLUMN hard_due_date INT REFERENCES config.hard_due_date (id);
+
+ALTER TABLE config.rule_circ_duration DROP COLUMN date_ceiling;
+
+CREATE OR REPLACE FUNCTION config.update_hard_due_dates () RETURNS INT AS $func$
+DECLARE
+    temp_value  config.hard_due_date_values%ROWTYPE;
+    updated     INT := 0;
+BEGIN
+    FOR temp_value IN
+      SELECT  DISTINCT ON (hard_due_date) *
+        FROM  config.hard_due_date_values
+        WHERE active_date <= NOW() -- We've passed (or are at) the rollover time
+        ORDER BY active_date DESC -- Latest (nearest to us) active time
+   LOOP
+        UPDATE  config.hard_due_date
+          SET   ceiling_date = temp_value.ceiling_date
+          WHERE id = temp_value.hard_due_date
+                AND ceiling_date <> temp_value.ceiling_date; -- Time is equal if we've already updated the chdd
+
+        IF FOUND THEN
+            updated := updated + 1;
+        END IF;
+    END LOOP;
+
+    RETURN updated;
+END;
+$func$ LANGUAGE plpgsql;
+
 CREATE OR REPLACE FUNCTION oils_text_as_bytea (TEXT) RETURNS BYTEA AS $_$
     SELECT CAST(REGEXP_REPLACE($1, $$\\$$, $$\\\\$$, 'g') AS BYTEA);
 $_$ LANGUAGE SQL IMMUTABLE;
@@ -23,17 +68,6 @@
 ALTER TABLE permission.grp_tree
 	ADD COLUMN hold_priority INT NOT NULL DEFAULT 0;
 
-ALTER TABLE config.rule_circ_duration
-	ADD COLUMN date_ceiling TIMESTAMPTZ;
-
-CREATE TABLE config.hard_due_date (
-	id              SERIAL      PRIMARY KEY,
-	duration_rule   INT         NOT NULL REFERENCES config.rule_circ_duration (id)
-	                            DEFERRABLE INITIALLY DEFERRED,
-	ceiling_date    TIMESTAMPTZ NOT NULL,
-	active_date     TIMESTAMPTZ NOT NULL
-);
-
 INSERT INTO container.biblio_record_entry_bucket_type (code,label) VALUES ('template_merge','Template Merge Container');
 
 CREATE OR REPLACE FUNCTION vandelay.strip_field ( xml TEXT, field TEXT ) RETURNS TEXT AS $_$



More information about the open-ils-commits mailing list