Make database schema patch dependencies work more better
authorDan Scott <dan@coffeecode.net>
Tue, 31 May 2011 21:30:31 +0000 (17:30 -0400)
committerBill Erickson <berick@esilibrary.com>
Wed, 1 Jun 2011 13:17:41 +0000 (09:17 -0400)
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@laurentian.ca>
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/src/sql/Pg/000.functions.general.sql
Open-ILS/src/sql/Pg/002.schema.config.sql
Open-ILS/src/sql/Pg/upgrade/0526.schema.upgrade-dep-tracking.sql

index 2bf6340..52301a4 100644 (file)
@@ -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;
index b98e2de..4bc5fad 100644 (file)
@@ -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)
index d455ee4..86b381d 100644 (file)
@@ -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)