[open-ils-commits] r17634 - in trunk/Open-ILS/src/sql/Pg: . upgrade (miker)
svn at svn.open-ils.org
svn at svn.open-ils.org
Mon Sep 13 13:26:07 EDT 2010
Author: miker
Date: 2010-09-13 13:26:03 -0400 (Mon, 13 Sep 2010)
New Revision: 17634
Added:
trunk/Open-ILS/src/sql/Pg/upgrade/0393.schema.perm-id-change-i18n-protection.sql
Modified:
trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
trunk/Open-ILS/src/sql/Pg/006.schema.permissions.sql
Log:
we need to move permissions around for a Great Renumbering, but i18n is not protected by fkeys. this provides infratructure for maintaining i18n values that already exist in a db, and an example usage on permission.perm_list
Modified: trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/002.schema.config.sql 2010-09-13 16:37:05 UTC (rev 17633)
+++ trunk/Open-ILS/src/sql/Pg/002.schema.config.sql 2010-09-13 17:26:03 UTC (rev 17634)
@@ -68,7 +68,7 @@
install_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
);
-INSERT INTO config.upgrade_log (version) VALUES ('0392'); -- phasefx
+INSERT INTO config.upgrade_log (version) VALUES ('0393'); -- miker
CREATE TABLE config.bib_source (
id SERIAL PRIMARY KEY,
@@ -647,6 +647,34 @@
CREATE UNIQUE INDEX i18n_identity ON config.i18n_core (fq_field,identity_value,translation);
+CREATE OR REPLACE FUNCTION oils_i18n_update_apply(old_ident TEXT, new_ident TEXT, hint TEXT) RETURNS VOID AS $_$
+BEGIN
+
+ EXECUTE $$
+ UPDATE config.i18n_core
+ SET identity_value = $$ || quote_literal(new_ident) || $$
+ WHERE fq_field LIKE '$$ || hint || $$.%'
+ AND identity_value = $$ || quote_literal(old_ident) || $$::TEXT;$$;
+
+ RETURN;
+
+END;
+$_$ LANGUAGE PLPGSQL;
+
+CREATE OR REPLACE FUNCTION oils_i18n_id_tracking(/* hint */) RETURNS TRIGGER AS $_$
+BEGIN
+ PERFORM oils_i18n_update_apply( OLD.id::TEXT, NEW.id::TEXT, TG_ARGV[0]::TEXT );
+ RETURN NEW;
+END;
+$_$ LANGUAGE PLPGSQL;
+
+CREATE OR REPLACE FUNCTION oils_i18n_code_tracking(/* hint */) RETURNS TRIGGER AS $_$
+BEGIN
+ PERFORM oils_i18n_update_apply( OLD.code::TEXT, NEW.code::TEXT, TG_ARGV[0]::TEXT );
+ RETURN NEW;
+END;
+$_$ LANGUAGE PLPGSQL;
+
CREATE TABLE config.billing_type (
id SERIAL PRIMARY KEY,
name TEXT NOT NULL,
Modified: trunk/Open-ILS/src/sql/Pg/006.schema.permissions.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/006.schema.permissions.sql 2010-09-13 16:37:05 UTC (rev 17633)
+++ trunk/Open-ILS/src/sql/Pg/006.schema.permissions.sql 2010-09-13 17:26:03 UTC (rev 17634)
@@ -27,6 +27,9 @@
description TEXT
);
CREATE INDEX perm_list_code_idx ON permission.perm_list (code);
+CREATE TRIGGER maintain_perm_i18n_tgr
+ AFTER UPDATE ON permission.perm_list
+ FOR EACH ROW EXECUTE PROCEDURE oils_i18n_id_tracking('ppl');
CREATE TABLE permission.grp_tree (
id SERIAL PRIMARY KEY,
Added: trunk/Open-ILS/src/sql/Pg/upgrade/0393.schema.perm-id-change-i18n-protection.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/upgrade/0393.schema.perm-id-change-i18n-protection.sql (rev 0)
+++ trunk/Open-ILS/src/sql/Pg/upgrade/0393.schema.perm-id-change-i18n-protection.sql 2010-09-13 17:26:03 UTC (rev 17634)
@@ -0,0 +1,38 @@
+BEGIN;
+
+INSERT INTO config.upgrade_log (version) VALUES ('0393'); -- miker
+
+CREATE OR REPLACE FUNCTION oils_i18n_update_apply(old_ident TEXT, new_ident TEXT, hint TEXT) RETURNS VOID AS $_$
+BEGIN
+
+ EXECUTE $$
+ UPDATE config.i18n_core
+ SET identity_value = $$ || new_ident || $$
+ WHERE fq_field LIKE '$$ || hint || $$.%'
+ AND identity_value = $$ || old_ident || $$;$$;
+
+ RETURN;
+
+END;
+$_$ LANGUAGE PLPGSQL;
+
+CREATE OR REPLACE FUNCTION oils_i18n_id_tracking(/* hint */) RETURNS TRIGGER AS $_$
+BEGIN
+ PERFORM oils_i18n_update_apply( OLD.id::TEXT, NEW.id::TEXT, TG_ARGV[0]::TEXT );
+ RETURN NEW;
+END;
+$_$ LANGUAGE PLPGSQL;
+
+CREATE OR REPLACE FUNCTION oils_i18n_code_tracking(/* hint */) RETURNS TRIGGER AS $_$
+BEGIN
+ PERFORM oils_i18n_update_apply( OLD.code::TEXT, NEW.code::TEXT, TG_ARGV[0]::TEXT );
+ RETURN NEW;
+END;
+$_$ LANGUAGE PLPGSQL;
+
+
+CREATE TRIGGER maintain_perm_i18n_tgr
+ AFTER UPDATE ON permission.perm_list
+ FOR EACH ROW EXECUTE PROCEDURE oils_i18n_tracking('ppl', 'id');
+
+COMMIT;
More information about the open-ils-commits
mailing list