[open-ils-commits] r18988 - in branches/rel_1_6/Open-ILS/src/sql/Pg: . upgrade (erickson)
svn at svn.open-ils.org
svn at svn.open-ils.org
Mon Dec 13 11:24:30 EST 2010
Author: erickson
Date: 2010-12-13 11:24:28 -0500 (Mon, 13 Dec 2010)
New Revision: 18988
Added:
branches/rel_1_6/Open-ILS/src/sql/Pg/upgrade/0470.schema.config_update_hard_due_dates_repairs.sql
Modified:
branches/rel_1_6/Open-ILS/src/sql/Pg/002.schema.config.sql
Log:
repaired order-by in update_hard_due_dates function to prevent sql errors
Modified: branches/rel_1_6/Open-ILS/src/sql/Pg/002.schema.config.sql
===================================================================
--- branches/rel_1_6/Open-ILS/src/sql/Pg/002.schema.config.sql 2010-12-13 16:22:19 UTC (rev 18987)
+++ branches/rel_1_6/Open-ILS/src/sql/Pg/002.schema.config.sql 2010-12-13 16:24:28 UTC (rev 18988)
@@ -292,7 +292,6 @@
active_date TIMESTAMPTZ NOT NULL
);
-
CREATE OR REPLACE FUNCTION config.update_hard_due_dates () RETURNS INT AS $func$
DECLARE
temp_value config.hard_due_date_values%ROWTYPE;
@@ -302,7 +301,7 @@
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
+ ORDER BY hard_due_date, active_date DESC -- Latest (nearest to us) active time
LOOP
UPDATE config.hard_due_date
SET ceiling_date = temp_value.ceiling_date
Copied: branches/rel_1_6/Open-ILS/src/sql/Pg/upgrade/0470.schema.config_update_hard_due_dates_repairs.sql (from rev 18985, trunk/Open-ILS/src/sql/Pg/upgrade/0470.schema.config_update_hard_due_dates_repairs.sql)
===================================================================
--- branches/rel_1_6/Open-ILS/src/sql/Pg/upgrade/0470.schema.config_update_hard_due_dates_repairs.sql (rev 0)
+++ branches/rel_1_6/Open-ILS/src/sql/Pg/upgrade/0470.schema.config_update_hard_due_dates_repairs.sql 2010-12-13 16:24:28 UTC (rev 18988)
@@ -0,0 +1,30 @@
+BEGIN;
+
+INSERT INTO config.upgrade_log (version) VALUES ('0470');
+
+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 hard_due_date, 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;
+
+COMMIT;
More information about the open-ils-commits
mailing list