From: miker Date: Mon, 13 Dec 2010 17:52:33 +0000 (+0000) Subject: Backport of r18988 from rel_1_6: repaired order-by in update_hard_due_dates function... X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=f623687f555cc72d6efbd74c627ee4dff8eddac1;p=Evergreen.git Backport of r18988 from rel_1_6: repaired order-by in update_hard_due_dates function to prevent sql errors git-svn-id: svn://svn.open-ils.org/ILS/branches/rel_1_6_2@18993 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql index e942ebc307..6b3399b05c 100644 --- a/Open-ILS/src/sql/Pg/002.schema.config.sql +++ b/Open-ILS/src/sql/Pg/002.schema.config.sql @@ -292,7 +292,6 @@ CREATE TABLE config.hard_due_date_values ( 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 @@ BEGIN 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 diff --git a/Open-ILS/src/sql/Pg/upgrade/0470.schema.config_update_hard_due_dates_repairs.sql b/Open-ILS/src/sql/Pg/upgrade/0470.schema.config_update_hard_due_dates_repairs.sql new file mode 100644 index 0000000000..b6b4c3a048 --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/0470.schema.config_update_hard_due_dates_repairs.sql @@ -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;