From: Ben Shum Date: Wed, 3 May 2017 01:51:13 +0000 (-0400) Subject: LP#1427392: Stamping upgrade script for hard due date value fix X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=825f4aaf8e407a42ddd30ce558303696aa7ecd47;p=working%2FEvergreen.git LP#1427392: Stamping upgrade script for hard due date value fix Signed-off-by: Ben Shum --- diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql index c74e22388e..2655c17c0b 100644 --- a/Open-ILS/src/sql/Pg/002.schema.config.sql +++ b/Open-ILS/src/sql/Pg/002.schema.config.sql @@ -90,7 +90,7 @@ CREATE TRIGGER no_overlapping_deps BEFORE INSERT OR UPDATE ON config.db_patch_dependencies FOR EACH ROW EXECUTE PROCEDURE evergreen.array_overlap_check ('deprecates'); -INSERT INTO config.upgrade_log (version, applied_to) VALUES ('1035', :eg_version); -- dyrcona/gmcharlt +INSERT INTO config.upgrade_log (version, applied_to) VALUES ('1036', :eg_version); -- mmorgan/bshum CREATE TABLE config.bib_source ( id SERIAL PRIMARY KEY, diff --git a/Open-ILS/src/sql/Pg/upgrade/1036.function.config_update_hard_due_dates_ceiling_date_fix.sql b/Open-ILS/src/sql/Pg/upgrade/1036.function.config_update_hard_due_dates_ceiling_date_fix.sql new file mode 100644 index 0000000000..e9f45c2fad --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/1036.function.config_update_hard_due_dates_ceiling_date_fix.sql @@ -0,0 +1,31 @@ +BEGIN; + +SELECT evergreen.upgrade_deps_block_check('1036', :eg_version); + +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 + AND temp_value.ceiling_date >= NOW(); -- Don't update ceiling dates to the past + + IF FOUND THEN + updated := updated + 1; + END IF; + END LOOP; + + RETURN updated; +END; +$func$ LANGUAGE plpgsql; + +COMMIT; diff --git a/Open-ILS/src/sql/Pg/upgrade/xxxx.function.config_update_hard_due_dates_ceiling_date_fix.sql b/Open-ILS/src/sql/Pg/upgrade/xxxx.function.config_update_hard_due_dates_ceiling_date_fix.sql deleted file mode 100644 index 33ec9e3747..0000000000 --- a/Open-ILS/src/sql/Pg/upgrade/xxxx.function.config_update_hard_due_dates_ceiling_date_fix.sql +++ /dev/null @@ -1,29 +0,0 @@ -BEGIN; - -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 - AND temp_value.ceiling_date >= NOW(); -- Don't update ceiling dates to the past - - IF FOUND THEN - updated := updated + 1; - END IF; - END LOOP; - - RETURN updated; -END; -$func$ LANGUAGE plpgsql; - -COMMIT;