3 INSERT INTO config.upgrade_log (version) VALUES ('0442'); -- tsbere via miker
5 DROP TABLE config.hard_due_date;
7 CREATE TABLE config.hard_due_date (
9 name TEXT NOT NULL UNIQUE CHECK ( name ~ E'^\\w+$' ),
10 ceiling_date TIMESTAMPTZ NOT NULL,
11 forceto BOOL NOT NULL,
15 CREATE TABLE config.hard_due_date_values (
16 id SERIAL PRIMARY KEY,
17 hard_due_date INT NOT NULL REFERENCES config.hard_due_date (id)
18 DEFERRABLE INITIALLY DEFERRED,
19 ceiling_date TIMESTAMPTZ NOT NULL,
20 active_date TIMESTAMPTZ NOT NULL
23 ALTER TABLE config.circ_matrix_matchpoint ADD COLUMN hard_due_date INT REFERENCES config.hard_due_date (id);
25 ALTER TABLE config.rule_circ_duration DROP COLUMN date_ceiling;
27 CREATE OR REPLACE FUNCTION config.update_hard_due_dates () RETURNS INT AS $func$
29 temp_value config.hard_due_date_values%ROWTYPE;
33 SELECT DISTINCT ON (hard_due_date) *
34 FROM config.hard_due_date_values
35 WHERE active_date <= NOW() -- We've passed (or are at) the rollover time
36 ORDER BY active_date DESC -- Latest (nearest to us) active time
38 UPDATE config.hard_due_date
39 SET ceiling_date = temp_value.ceiling_date
40 WHERE id = temp_value.hard_due_date
41 AND ceiling_date <> temp_value.ceiling_date; -- Time is equal if we've already updated the chdd
44 updated := updated + 1;
50 $func$ LANGUAGE plpgsql;