[open-ils-commits] [GIT] Evergreen ILS branch master updated. 1aea64df0480c23cf895d637c1846d2974da5f97

Evergreen Git git at git.evergreen-ils.org
Wed Jun 1 09:18:33 EDT 2011


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Evergreen ILS".

The branch, master has been updated
       via  1aea64df0480c23cf895d637c1846d2974da5f97 (commit)
       via  340e026918ecca3ab7dfef6a67160ed516cca835 (commit)
      from  501f26fe7f0da1d4a5d6962b2c3a820eec3ccc4d (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 1aea64df0480c23cf895d637c1846d2974da5f97
Author: Dan Scott <dan at coffeecode.net>
Date:   Tue May 31 17:30:31 2011 -0400

    Make database schema patch dependencies work more better
    
    Per a suggestion from Bill Erickson, move evergreen_patch into the
    evergreen schema (where we can simply call it evergreen.patch).
    
    Also, as we seem doomed to repeat ourselves, add a little bit of schema
    adjustment to the 0526 upgrade script so it can be applied
    retroactively.
    
    Signed-off-by: Dan Scott <dscott at laurentian.ca>
    Signed-off-by: Bill Erickson <berick at esilibrary.com>

diff --git a/Open-ILS/src/sql/Pg/000.functions.general.sql b/Open-ILS/src/sql/Pg/000.functions.general.sql
index 2bf6340..52301a4 100644
--- a/Open-ILS/src/sql/Pg/000.functions.general.sql
+++ b/Open-ILS/src/sql/Pg/000.functions.general.sql
@@ -26,4 +26,7 @@ CREATE OR REPLACE FUNCTION evergreen.xml_escape(str TEXT) RETURNS text AS $$
        '>', '&gt;');
 $$ LANGUAGE SQL IMMUTABLE;
 
+-- Provide a named type for patching functions
+CREATE TYPE evergreen.patch AS (patch TEXT);
+
 COMMIT;
diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql
index b98e2de..4bc5fad 100644
--- a/Open-ILS/src/sql/Pg/002.schema.config.sql
+++ b/Open-ILS/src/sql/Pg/002.schema.config.sql
@@ -823,10 +823,8 @@ BEGIN
 END;
 $$ LANGUAGE PLPGSQL;
 
-CREATE TYPE evergreen_patch AS (patch TEXT);
-
 -- List applied db patches that are deprecated by (and block the application of) my_db_patch
-CREATE OR REPLACE FUNCTION evergreen.upgrade_list_applied_deprecates ( my_db_patch TEXT ) RETURNS SETOF evergreen_patch AS $$
+CREATE OR REPLACE FUNCTION evergreen.upgrade_list_applied_deprecates ( my_db_patch TEXT ) RETURNS SETOF evergreen.patch AS $$
     SELECT  DISTINCT l.version
       FROM  config.upgrade_log l
             JOIN config.db_patch_dependencies d ON (l.version::TEXT[] && d.deprecates)
@@ -834,7 +832,7 @@ CREATE OR REPLACE FUNCTION evergreen.upgrade_list_applied_deprecates ( my_db_pat
 $$ LANGUAGE SQL;
 
 -- List applied db patches that are superseded by (and block the application of) my_db_patch
-CREATE OR REPLACE FUNCTION evergreen.upgrade_list_applied_supersedes ( my_db_patch TEXT ) RETURNS SETOF evergreen_patch AS $$
+CREATE OR REPLACE FUNCTION evergreen.upgrade_list_applied_supersedes ( my_db_patch TEXT ) RETURNS SETOF evergreen.patch AS $$
     SELECT  DISTINCT l.version
       FROM  config.upgrade_log l
             JOIN config.db_patch_dependencies d ON (l.version::TEXT[] && d.supersedes)
diff --git a/Open-ILS/src/sql/Pg/upgrade/0526.schema.upgrade-dep-tracking.sql b/Open-ILS/src/sql/Pg/upgrade/0526.schema.upgrade-dep-tracking.sql
index d455ee4..86b381d 100644
--- a/Open-ILS/src/sql/Pg/upgrade/0526.schema.upgrade-dep-tracking.sql
+++ b/Open-ILS/src/sql/Pg/upgrade/0526.schema.upgrade-dep-tracking.sql
@@ -1,3 +1,10 @@
+-- DROP objects that might have existed from a prior run of 0526
+-- Yes this is ironic.
+DROP TABLE IF EXISTS config.db_patch_dependencies;
+ALTER TABLE config.upgrade_log DROP COLUMN applied_to;
+DROP FUNCTION evergreen.upgrade_list_applied_deprecates(TEXT);
+DROP FUNCTION evergreen.upgrade_list_applied_supersedes(TEXT);
+
 BEGIN;
 
 INSERT INTO config.upgrade_log (version) VALUES ('0526'); --miker
@@ -33,10 +40,11 @@ CREATE TRIGGER no_overlapping_deps
 ALTER TABLE config.upgrade_log
     ADD COLUMN applied_to TEXT;
 
-CREATE TYPE evergreen_patch AS (patch TEXT);
+-- Provide a named type for patching functions
+CREATE TYPE evergreen.patch AS (patch TEXT);
 
 -- List applied db patches that are deprecated by (and block the application of) my_db_patch
-CREATE OR REPLACE FUNCTION evergreen.upgrade_list_applied_deprecates ( my_db_patch TEXT ) RETURNS SETOF evergreen_patch AS $$
+CREATE OR REPLACE FUNCTION evergreen.upgrade_list_applied_deprecates ( my_db_patch TEXT ) RETURNS SETOF evergreen.patch AS $$
     SELECT  DISTINCT l.version
       FROM  config.upgrade_log l
             JOIN config.db_patch_dependencies d ON (l.version::TEXT[] && d.deprecates)
@@ -44,7 +52,7 @@ CREATE OR REPLACE FUNCTION evergreen.upgrade_list_applied_deprecates ( my_db_pat
 $$ LANGUAGE SQL;
 
 -- List applied db patches that are superseded by (and block the application of) my_db_patch
-CREATE OR REPLACE FUNCTION evergreen.upgrade_list_applied_supersedes ( my_db_patch TEXT ) RETURNS SETOF evergreen_patch AS $$
+CREATE OR REPLACE FUNCTION evergreen.upgrade_list_applied_supersedes ( my_db_patch TEXT ) RETURNS SETOF evergreen.patch AS $$
     SELECT  DISTINCT l.version
       FROM  config.upgrade_log l
             JOIN config.db_patch_dependencies d ON (l.version::TEXT[] && d.supersedes)

commit 340e026918ecca3ab7dfef6a67160ed516cca835
Author: Dan Scott <dan at coffeecode.net>
Date:   Tue May 31 13:19:08 2011 -0400

    Make patch-checking function able to raise a notice
    
    There's probably a more elegant way to do this, but basic
    testing with the following at least didn't throw an error:
    
    SELECT evergreen.upgrade_deps_block_check('XXXX', NULL);
    
    Also note that the CREATE OR REPLACE function calls will
    fail on an existing database due to the changed return
    type of the functions - so if this gets moved into its
    own upgrade script, DROP FUNCTION calls will be
    required.
    
    Signed-off-by: Dan Scott <dscott at laurentian.ca>
    Signed-off-by: Bill Erickson <berick at esilibrary.com>

diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql
index 822623b..b98e2de 100644
--- a/Open-ILS/src/sql/Pg/002.schema.config.sql
+++ b/Open-ILS/src/sql/Pg/002.schema.config.sql
@@ -823,20 +823,22 @@ BEGIN
 END;
 $$ LANGUAGE PLPGSQL;
 
+CREATE TYPE evergreen_patch AS (patch TEXT);
+
 -- List applied db patches that are deprecated by (and block the application of) my_db_patch
-CREATE OR REPLACE FUNCTION evergreen.upgrade_list_applied_deprecates ( my_db_patch TEXT ) RETURNS SETOF TEXT AS $$
+CREATE OR REPLACE FUNCTION evergreen.upgrade_list_applied_deprecates ( my_db_patch TEXT ) RETURNS SETOF evergreen_patch AS $$
     SELECT  DISTINCT l.version
       FROM  config.upgrade_log l
             JOIN config.db_patch_dependencies d ON (l.version::TEXT[] && d.deprecates)
-      WHERE d.db_patch = $1 
+      WHERE d.db_patch = $1
 $$ LANGUAGE SQL;
 
 -- List applied db patches that are superseded by (and block the application of) my_db_patch
-CREATE OR REPLACE FUNCTION evergreen.upgrade_list_applied_supersedes ( my_db_patch TEXT ) RETURNS SETOF TEXT AS $$
+CREATE OR REPLACE FUNCTION evergreen.upgrade_list_applied_supersedes ( my_db_patch TEXT ) RETURNS SETOF evergreen_patch AS $$
     SELECT  DISTINCT l.version
       FROM  config.upgrade_log l
             JOIN config.db_patch_dependencies d ON (l.version::TEXT[] && d.supersedes)
-      WHERE d.db_patch = $1 
+      WHERE d.db_patch = $1
 $$ LANGUAGE SQL;
 
 -- List applied db patches that deprecates (and block the application of) my_db_patch
@@ -865,10 +867,15 @@ CREATE OR REPLACE FUNCTION evergreen.upgrade_verify_no_dep_conflicts ( my_db_pat
              SELECT * FROM evergreen.upgrade_list_applied_superseded( $1 ))x
 $$ LANGUAGE SQL;
 
--- Raise an exception if there are, in fact, dep/sup confilct
+-- Raise an exception if there are, in fact, dep/sup conflict
 CREATE OR REPLACE FUNCTION evergreen.upgrade_deps_block_check ( my_db_patch TEXT, my_applied_to TEXT ) RETURNS BOOL AS $$
+DECLARE 
+    deprecates TEXT;
+    supersedes TEXT;
 BEGIN
     IF NOT evergreen.upgrade_verify_no_dep_conflicts( my_db_patch ) THEN
+        SELECT  STRING_AGG(patch, ', ') INTO deprecates FROM evergreen.upgrade_list_applied_deprecates(my_db_patch);
+        SELECT  STRING_AGG(patch, ', ') INTO supersedes FROM evergreen.upgrade_list_applied_supersedes(my_db_patch);
         RAISE EXCEPTION '
 Upgrade script % can not be applied:
   applied deprecated scripts %
@@ -876,8 +883,8 @@ Upgrade script % can not be applied:
   deprecated by %
   superseded by %',
             my_db_patch,
-            ARRAY_AGG(evergreen.upgrade_list_applied_deprecates(my_db_patch)),
-            ARRAY_AGG(evergreen.upgrade_list_applied_supersedes(my_db_patch)),
+            deprecates,
+            supersedes,
             evergreen.upgrade_list_applied_deprecated(my_db_patch),
             evergreen.upgrade_list_applied_superseded(my_db_patch);
     END IF;
diff --git a/Open-ILS/src/sql/Pg/upgrade/0526.schema.upgrade-dep-tracking.sql b/Open-ILS/src/sql/Pg/upgrade/0526.schema.upgrade-dep-tracking.sql
index 42de078..d455ee4 100644
--- a/Open-ILS/src/sql/Pg/upgrade/0526.schema.upgrade-dep-tracking.sql
+++ b/Open-ILS/src/sql/Pg/upgrade/0526.schema.upgrade-dep-tracking.sql
@@ -33,8 +33,10 @@ CREATE TRIGGER no_overlapping_deps
 ALTER TABLE config.upgrade_log
     ADD COLUMN applied_to TEXT;
 
+CREATE TYPE evergreen_patch AS (patch TEXT);
+
 -- List applied db patches that are deprecated by (and block the application of) my_db_patch
-CREATE OR REPLACE FUNCTION evergreen.upgrade_list_applied_deprecates ( my_db_patch TEXT ) RETURNS SETOF TEXT AS $$
+CREATE OR REPLACE FUNCTION evergreen.upgrade_list_applied_deprecates ( my_db_patch TEXT ) RETURNS SETOF evergreen_patch AS $$
     SELECT  DISTINCT l.version
       FROM  config.upgrade_log l
             JOIN config.db_patch_dependencies d ON (l.version::TEXT[] && d.deprecates)
@@ -42,7 +44,7 @@ CREATE OR REPLACE FUNCTION evergreen.upgrade_list_applied_deprecates ( my_db_pat
 $$ LANGUAGE SQL;
 
 -- List applied db patches that are superseded by (and block the application of) my_db_patch
-CREATE OR REPLACE FUNCTION evergreen.upgrade_list_applied_supersedes ( my_db_patch TEXT ) RETURNS SETOF TEXT AS $$
+CREATE OR REPLACE FUNCTION evergreen.upgrade_list_applied_supersedes ( my_db_patch TEXT ) RETURNS SETOF evergreen_patch AS $$
     SELECT  DISTINCT l.version
       FROM  config.upgrade_log l
             JOIN config.db_patch_dependencies d ON (l.version::TEXT[] && d.supersedes)
@@ -77,8 +79,13 @@ $$ LANGUAGE SQL;
 
 -- Raise an exception if there are, in fact, dep/sup confilct
 CREATE OR REPLACE FUNCTION evergreen.upgrade_deps_block_check ( my_db_patch TEXT, my_applied_to TEXT ) RETURNS BOOL AS $$
+DECLARE 
+    deprecates TEXT;
+    supersedes TEXT;
 BEGIN
     IF NOT evergreen.upgrade_verify_no_dep_conflicts( my_db_patch ) THEN
+        SELECT  STRING_AGG(patch, ', ') INTO deprecates FROM evergreen.upgrade_list_applied_deprecates(my_db_patch);
+        SELECT  STRING_AGG(patch, ', ') INTO supersedes FROM evergreen.upgrade_list_applied_supersedes(my_db_patch);
         RAISE EXCEPTION '
 Upgrade script % can not be applied:
   applied deprecated scripts %
@@ -86,8 +93,8 @@ Upgrade script % can not be applied:
   deprecated by %
   superseded by %',
             my_db_patch,
-            ARRAY_AGG(evergreen.upgrade_list_applied_deprecates(my_db_patch)),
-            ARRAY_AGG(evergreen.upgrade_list_applied_supersedes(my_db_patch)),
+            deprecates,
+            supersedes,
             evergreen.upgrade_list_applied_deprecated(my_db_patch),
             evergreen.upgrade_list_applied_superseded(my_db_patch);
     END IF;

-----------------------------------------------------------------------

Summary of changes:
 Open-ILS/src/sql/Pg/000.functions.general.sql      |    3 ++
 Open-ILS/src/sql/Pg/002.schema.config.sql          |   19 ++++++++++------
 .../upgrade/0526.schema.upgrade-dep-tracking.sql   |   23 ++++++++++++++++---
 3 files changed, 34 insertions(+), 11 deletions(-)


hooks/post-receive
-- 
Evergreen ILS


More information about the open-ils-commits mailing list