LP#1410369 stamping TPAC message center DB upgrade
authorBill Erickson <berickxx@gmail.com>
Fri, 20 Feb 2015 21:55:40 +0000 (16:55 -0500)
committerBill Erickson <berickxx@gmail.com>
Fri, 20 Feb 2015 21:58:18 +0000 (16:58 -0500)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/sql/Pg/002.schema.config.sql
Open-ILS/src/sql/Pg/upgrade/0910.schema.message-center.sql [new file with mode: 0644]
Open-ILS/src/sql/Pg/upgrade/0911.data.message-center.sql [new file with mode: 0644]
Open-ILS/src/sql/Pg/upgrade/XXXX.schema.message-center.sql [deleted file]
Open-ILS/src/sql/Pg/upgrade/YYYY.data.message-center.sql [deleted file]

index bc665c1..39f93ce 100644 (file)
@@ -91,7 +91,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 ('0909', :eg_version); -- berick/miker
+INSERT INTO config.upgrade_log (version, applied_to) VALUES ('0911', :eg_version); -- miker/gmcharlt/berick
 
 CREATE TABLE config.bib_source (
        id              SERIAL  PRIMARY KEY,
diff --git a/Open-ILS/src/sql/Pg/upgrade/0910.schema.message-center.sql b/Open-ILS/src/sql/Pg/upgrade/0910.schema.message-center.sql
new file mode 100644 (file)
index 0000000..181eeb2
--- /dev/null
@@ -0,0 +1,79 @@
+BEGIN;
+
+SELECT evergreen.upgrade_deps_block_check('0910', :eg_version);
+
+CREATE TABLE actor.usr_message (
+    id          SERIAL                      PRIMARY KEY,
+    usr         INT                         NOT NULL REFERENCES actor.usr (id) DEFERRABLE INITIALLY DEFERRED,
+    title       TEXT,
+    message     TEXT                        NOT NULL,
+    create_date TIMESTAMP WITH TIME ZONE    NOT NULL DEFAULT NOW(),
+    deleted     BOOL                        NOT NULL DEFAULT FALSE,
+    read_date   TIMESTAMP WITH TIME ZONE,
+    sending_lib INT                         NOT NULL REFERENCES actor.org_unit (id) DEFERRABLE INITIALLY DEFERRED
+);
+CREATE INDEX aum_usr ON actor.usr_message (usr);
+
+CREATE RULE protect_usr_message_delete AS
+    ON DELETE TO actor.usr_message DO INSTEAD (
+        UPDATE actor.usr_message
+            SET deleted = TRUE
+            WHERE OLD.id = actor.usr_message.id
+    );
+
+ALTER TABLE action_trigger.event_definition
+    ADD COLUMN message_template TEXT,
+    ADD COLUMN message_usr_path TEXT,
+    ADD COLUMN message_library_path TEXT,
+    ADD COLUMN message_title TEXT;
+
+CREATE FUNCTION actor.convert_usr_note_to_message () RETURNS TRIGGER AS $$
+BEGIN
+    IF NEW.pub THEN
+        IF TG_OP = 'UPDATE' THEN
+            IF OLD.pub = TRUE THEN
+                RETURN NEW;
+            END IF;
+        END IF;
+
+        INSERT INTO actor.usr_message (usr, title, message, sending_lib)
+            VALUES (NEW.usr, NEW.title, NEW.value, (SELECT home_ou FROM actor.usr WHERE id = NEW.creator));
+    END IF;
+
+    RETURN NEW;
+END;
+$$ LANGUAGE PLPGSQL;
+
+CREATE TRIGGER convert_usr_note_to_message_tgr
+    AFTER INSERT OR UPDATE ON actor.usr_note
+    FOR EACH ROW EXECUTE PROCEDURE actor.convert_usr_note_to_message();
+
+CREATE VIEW actor.usr_message_limited
+AS SELECT * FROM actor.usr_message;
+
+CREATE FUNCTION actor.restrict_usr_message_limited () RETURNS TRIGGER AS $$
+BEGIN
+    IF TG_OP = 'UPDATE' THEN
+        UPDATE actor.usr_message
+        SET    read_date = NEW.read_date,
+               deleted   = NEW.deleted
+        WHERE  id = NEW.id;
+        RETURN NEW;
+    END IF;
+    RETURN NULL;
+END;
+$$ LANGUAGE PLPGSQL;
+
+CREATE TRIGGER restrict_usr_message_limited_tgr
+    INSTEAD OF UPDATE OR INSERT OR DELETE ON actor.usr_message_limited
+    FOR EACH ROW EXECUTE PROCEDURE actor.restrict_usr_message_limited();
+
+-- and copy over existing public user notes as (read) patron messages
+INSERT INTO actor.usr_message (usr, title, message, sending_lib, create_date, read_date)
+SELECT aun.usr, title, value, home_ou, aun.create_date, NOW()
+FROM actor.usr_note aun
+JOIN actor.usr au ON (au.id = aun.usr)
+WHERE aun.pub;
+
+COMMIT;
+
diff --git a/Open-ILS/src/sql/Pg/upgrade/0911.data.message-center.sql b/Open-ILS/src/sql/Pg/upgrade/0911.data.message-center.sql
new file mode 100644 (file)
index 0000000..96f04ab
--- /dev/null
@@ -0,0 +1,97 @@
+BEGIN;
+
+SELECT evergreen.upgrade_deps_block_check('0911', :eg_version);
+
+-- Auto-cancelled, no target
+INSERT INTO action_trigger.event_definition (
+    id, active, owner, name, hook,
+    validator, reactor, delay, delay_field,
+    group_field, message_usr_path, message_library_path, message_title,
+    message_template
+) VALUES (
+    51, FALSE, 1, 'Hold Cancelled (No Target) User Message', 'hold_request.cancel.expire_no_target',
+    'HoldIsCancelled', 'NOOP_True', '30 minutes', 'cancel_time',
+    'usr', 'usr', 'usr.home_ou', 'Hold Request Cancelled',
+$$
+[%- USE date -%]
+[%- user = target.0.usr -%]
+The following holds were cancelled because no items were found to fullfil them.
+
+[% FOR hold IN target %]
+    Title: [% hold.bib_rec.bib_record.simple_record.title %]
+    Author: [% hold.bib_rec.bib_record.simple_record.author %]
+    Library: [% hold.pickup_lib.name %]
+    Request Date: [% date.format(helpers.format_date(hold.request_time), '%Y-%m-%d') %]
+[% END %]
+
+$$);
+
+INSERT INTO action_trigger.environment (event_def, path) VALUES
+    (51, 'usr'),
+    (51, 'pickup_lib'),
+    (51, 'bib_rec.bib_record.simple_record');
+
+
+-- Cancelled by staff
+INSERT INTO action_trigger.event_definition (
+    id, active, owner, name, hook,
+    validator, reactor, delay, delay_field,
+    group_field, message_usr_path, message_library_path, message_title,
+    message_template
+) VALUES (
+    52, FALSE, 1, 'Hold Cancelled (Staff) User Message', 'hold_request.cancel.staff',
+    'HoldIsCancelled', 'NOOP_True', '30 minutes', 'cancel_time',
+    'usr', 'usr', 'usr.home_ou', 'Hold Request Cancelled',
+$$
+[%- USE date -%]
+[%- user = target.0.usr -%]
+The following holds were cancelled by a staff member.
+
+[% FOR hold IN target %]
+    Title: [% hold.bib_rec.bib_record.simple_record.title %]
+    Author: [% hold.bib_rec.bib_record.simple_record.author %]
+    Library: [% hold.pickup_lib.name %]
+    Request Date: [% date.format(helpers.format_date(hold.request_time), '%Y-%m-%d') %]
+    Cancellation Note: [% hold.cancel_note %]
+[% END %]
+
+$$);
+
+INSERT INTO action_trigger.environment (event_def, path) VALUES
+    (52, 'usr'),
+    (52, 'pickup_lib'),
+    (52, 'bib_rec.bib_record.simple_record');
+
+
+-- Shelf expired
+INSERT INTO action_trigger.event_definition (
+    id, active, owner, name, hook,
+    validator, reactor, delay, delay_field,
+    group_field, message_usr_path, message_library_path, message_title,
+    message_template
+) VALUES (
+    53, TRUE, 1, 'Hold Cancelled (Shelf-Expired) User Message', 'hold_request.cancel.expire_holds_shelf',
+    'HoldIsCancelled', 'NOOP_True', '30 minutes', 'cancel_time',
+    'usr', 'usr', 'usr.home_ou', 'Hold Request Cancelled',
+$$
+[%- USE date -%]
+[%- user = target.0.usr -%]
+The following holds were cancelled because they were never picked up.
+
+[% FOR hold IN target %]
+    Title: [% hold.bib_rec.bib_record.simple_record.title %]
+    Author: [% hold.bib_rec.bib_record.simple_record.author %]
+    Library: [% hold.pickup_lib.name %]
+    Request Date: [% date.format(helpers.format_date(hold.request_time), '%Y-%m-%d') %]
+    Pickup By: [% date.format(helpers.format_date(hold.shelf_expire_time), '%Y-%m-%d') %]
+[% END %]
+
+$$);
+
+INSERT INTO action_trigger.environment (event_def, path) VALUES
+    (53, 'usr'),
+    (53, 'pickup_lib'),
+    (53, 'bib_rec.bib_record.simple_record');
+
+COMMIT;
+
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.message-center.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.message-center.sql
deleted file mode 100644 (file)
index 7e47618..0000000
+++ /dev/null
@@ -1,79 +0,0 @@
-BEGIN;
-
-SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
-
-CREATE TABLE actor.usr_message (
-    id          SERIAL                      PRIMARY KEY,
-    usr         INT                         NOT NULL REFERENCES actor.usr (id) DEFERRABLE INITIALLY DEFERRED,
-    title       TEXT,
-    message     TEXT                        NOT NULL,
-    create_date TIMESTAMP WITH TIME ZONE    NOT NULL DEFAULT NOW(),
-    deleted     BOOL                        NOT NULL DEFAULT FALSE,
-    read_date   TIMESTAMP WITH TIME ZONE,
-    sending_lib INT                         NOT NULL REFERENCES actor.org_unit (id) DEFERRABLE INITIALLY DEFERRED
-);
-CREATE INDEX aum_usr ON actor.usr_message (usr);
-
-CREATE RULE protect_usr_message_delete AS
-    ON DELETE TO actor.usr_message DO INSTEAD (
-        UPDATE actor.usr_message
-            SET deleted = TRUE
-            WHERE OLD.id = actor.usr_message.id
-    );
-
-ALTER TABLE action_trigger.event_definition
-    ADD COLUMN message_template TEXT,
-    ADD COLUMN message_usr_path TEXT,
-    ADD COLUMN message_library_path TEXT,
-    ADD COLUMN message_title TEXT;
-
-CREATE FUNCTION actor.convert_usr_note_to_message () RETURNS TRIGGER AS $$
-BEGIN
-    IF NEW.pub THEN
-        IF TG_OP = 'UPDATE' THEN
-            IF OLD.pub = TRUE THEN
-                RETURN NEW;
-            END IF;
-        END IF;
-
-        INSERT INTO actor.usr_message (usr, title, message, sending_lib)
-            VALUES (NEW.usr, NEW.title, NEW.value, (SELECT home_ou FROM actor.usr WHERE id = NEW.creator));
-    END IF;
-
-    RETURN NEW;
-END;
-$$ LANGUAGE PLPGSQL;
-
-CREATE TRIGGER convert_usr_note_to_message_tgr
-    AFTER INSERT OR UPDATE ON actor.usr_note
-    FOR EACH ROW EXECUTE PROCEDURE actor.convert_usr_note_to_message();
-
-CREATE VIEW actor.usr_message_limited
-AS SELECT * FROM actor.usr_message;
-
-CREATE FUNCTION actor.restrict_usr_message_limited () RETURNS TRIGGER AS $$
-BEGIN
-    IF TG_OP = 'UPDATE' THEN
-        UPDATE actor.usr_message
-        SET    read_date = NEW.read_date,
-               deleted   = NEW.deleted
-        WHERE  id = NEW.id;
-        RETURN NEW;
-    END IF;
-    RETURN NULL;
-END;
-$$ LANGUAGE PLPGSQL;
-
-CREATE TRIGGER restrict_usr_message_limited_tgr
-    INSTEAD OF UPDATE OR INSERT OR DELETE ON actor.usr_message_limited
-    FOR EACH ROW EXECUTE PROCEDURE actor.restrict_usr_message_limited();
-
--- and copy over existing public user notes as (read) patron messages
-INSERT INTO actor.usr_message (usr, title, message, sending_lib, create_date, read_date)
-SELECT aun.usr, title, value, home_ou, aun.create_date, NOW()
-FROM actor.usr_note aun
-JOIN actor.usr au ON (au.id = aun.usr)
-WHERE aun.pub;
-
-COMMIT;
-
diff --git a/Open-ILS/src/sql/Pg/upgrade/YYYY.data.message-center.sql b/Open-ILS/src/sql/Pg/upgrade/YYYY.data.message-center.sql
deleted file mode 100644 (file)
index e6ddf4c..0000000
+++ /dev/null
@@ -1,95 +0,0 @@
-BEGIN;
-
--- Auto-cancelled, no target
-INSERT INTO action_trigger.event_definition (
-    id, active, owner, name, hook,
-    validator, reactor, delay, delay_field,
-    group_field, message_usr_path, message_library_path, message_title,
-    message_template
-) VALUES (
-    51, FALSE, 1, 'Hold Cancelled (No Target) User Message', 'hold_request.cancel.expire_no_target',
-    'HoldIsCancelled', 'NOOP_True', '30 minutes', 'cancel_time',
-    'usr', 'usr', 'usr.home_ou', 'Hold Request Cancelled',
-$$
-[%- USE date -%]
-[%- user = target.0.usr -%]
-The following holds were cancelled because no items were found to fullfil them.
-
-[% FOR hold IN target %]
-    Title: [% hold.bib_rec.bib_record.simple_record.title %]
-    Author: [% hold.bib_rec.bib_record.simple_record.author %]
-    Library: [% hold.pickup_lib.name %]
-    Request Date: [% date.format(helpers.format_date(hold.request_time), '%Y-%m-%d') %]
-[% END %]
-
-$$);
-
-INSERT INTO action_trigger.environment (event_def, path) VALUES
-    (51, 'usr'),
-    (51, 'pickup_lib'),
-    (51, 'bib_rec.bib_record.simple_record');
-
-
--- Cancelled by staff
-INSERT INTO action_trigger.event_definition (
-    id, active, owner, name, hook,
-    validator, reactor, delay, delay_field,
-    group_field, message_usr_path, message_library_path, message_title,
-    message_template
-) VALUES (
-    52, FALSE, 1, 'Hold Cancelled (Staff) User Message', 'hold_request.cancel.staff',
-    'HoldIsCancelled', 'NOOP_True', '30 minutes', 'cancel_time',
-    'usr', 'usr', 'usr.home_ou', 'Hold Request Cancelled',
-$$
-[%- USE date -%]
-[%- user = target.0.usr -%]
-The following holds were cancelled by a staff member.
-
-[% FOR hold IN target %]
-    Title: [% hold.bib_rec.bib_record.simple_record.title %]
-    Author: [% hold.bib_rec.bib_record.simple_record.author %]
-    Library: [% hold.pickup_lib.name %]
-    Request Date: [% date.format(helpers.format_date(hold.request_time), '%Y-%m-%d') %]
-    Cancellation Note: [% hold.cancel_note %]
-[% END %]
-
-$$);
-
-INSERT INTO action_trigger.environment (event_def, path) VALUES
-    (52, 'usr'),
-    (52, 'pickup_lib'),
-    (52, 'bib_rec.bib_record.simple_record');
-
-
--- Shelf expired
-INSERT INTO action_trigger.event_definition (
-    id, active, owner, name, hook,
-    validator, reactor, delay, delay_field,
-    group_field, message_usr_path, message_library_path, message_title,
-    message_template
-) VALUES (
-    53, TRUE, 1, 'Hold Cancelled (Shelf-Expired) User Message', 'hold_request.cancel.expire_holds_shelf',
-    'HoldIsCancelled', 'NOOP_True', '30 minutes', 'cancel_time',
-    'usr', 'usr', 'usr.home_ou', 'Hold Request Cancelled',
-$$
-[%- USE date -%]
-[%- user = target.0.usr -%]
-The following holds were cancelled because they were never picked up.
-
-[% FOR hold IN target %]
-    Title: [% hold.bib_rec.bib_record.simple_record.title %]
-    Author: [% hold.bib_rec.bib_record.simple_record.author %]
-    Library: [% hold.pickup_lib.name %]
-    Request Date: [% date.format(helpers.format_date(hold.request_time), '%Y-%m-%d') %]
-    Pickup By: [% date.format(helpers.format_date(hold.shelf_expire_time), '%Y-%m-%d') %]
-[% END %]
-
-$$);
-
-INSERT INTO action_trigger.environment (event_def, path) VALUES
-    (53, 'usr'),
-    (53, 'pickup_lib'),
-    (53, 'bib_rec.bib_record.simple_record');
-
-COMMIT;
-