From 767cdb9c28130ec5ffaa37ef686bd488110d8abe Mon Sep 17 00:00:00 2001 From: miker Date: Wed, 20 Oct 2010 16:39:40 +0000 Subject: [PATCH] 1.6.1-2.0 upgrade script needs to fall in line with reality, re 0442 git-svn-id: svn://svn.open-ils.org/ILS/trunk@18411 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/sql/Pg/1.6.1-2.0-upgrade-db.sql | 45 ++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/Open-ILS/src/sql/Pg/1.6.1-2.0-upgrade-db.sql b/Open-ILS/src/sql/Pg/1.6.1-2.0-upgrade-db.sql index 43f225906c..94c703f3cf 100644 --- a/Open-ILS/src/sql/Pg/1.6.1-2.0-upgrade-db.sql +++ b/Open-ILS/src/sql/Pg/1.6.1-2.0-upgrade-db.sql @@ -6187,6 +6187,51 @@ ALTER TABLE action.circulation CHECK (stop_fines IN ( 'CHECKIN','CLAIMSRETURNED','LOST','MAXFINES','RENEW','LONGOVERDUE','CLAIMSNEVERCHECKEDOUT')); +-- Hard due-date functionality +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; + -- Correct some long-standing misspellings involving variations of "recur" ALTER TABLE action.circulation RENAME COLUMN recuring_fine TO recurring_fine; -- 2.11.0