upgrade script for actor.usr.last_update_date
authorJason Etheridge <jason@esilibrary.com>
Fri, 5 Aug 2011 10:58:07 +0000 (06:58 -0400)
committerThomas Berezansky <tsbere@mvlc.org>
Thu, 8 Sep 2011 19:40:16 +0000 (15:40 -0400)
Signed-off-by: Jason Etheridge <jason@esilibrary.com>
Signed-off-by: Thomas Berezansky <tsbere@mvlc.org>
Open-ILS/src/sql/Pg/upgrade/XXXX.schema.au_last_update_date.sql [new file with mode: 0644]

diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.au_last_update_date.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.au_last_update_date.sql
new file mode 100644 (file)
index 0000000..3b79291
--- /dev/null
@@ -0,0 +1,28 @@
+-- Evergreen DB patch XXXX.schema.au_last_update_date.sql
+BEGIN;
+
+-- check whether patch can be applied
+SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
+
+-- Add new column last_update_date to actor.usr, with trigger to maintain it
+-- Add corresponding new column to auditor.actor_usr_history
+
+ALTER TABLE actor.usr
+       ADD COLUMN last_update_date TIMESTAMPTZ;
+
+ALTER TABLE auditor.actor_usr_history
+       ADD COLUMN last_update_date TIMESTAMPTZ;
+
+CREATE OR REPLACE FUNCTION actor.au_updated()
+RETURNS TRIGGER AS $$
+BEGIN
+    NEW.last_update_date := now();
+       RETURN NEW;
+END;
+$$ LANGUAGE plpgsql;
+
+CREATE TRIGGER au_update_trig
+       BEFORE UPDATE ON actor.usr
+       FOR EACH ROW EXECUTE PROCEDURE actor.au_updated();
+
+COMMIT;