[open-ils-commits] r20341 - in trunk/Open-ILS/src/sql/Pg: . upgrade (miker)
svn at svn.open-ils.org
svn at svn.open-ils.org
Wed Apr 27 11:24:57 EDT 2011
Author: miker
Date: 2011-04-27 11:24:54 -0400 (Wed, 27 Apr 2011)
New Revision: 20341
Added:
trunk/Open-ILS/src/sql/Pg/upgrade/0526.schema.upgrade-dep-tracking.sql
Modified:
trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
Log:
support for depracate/supersede tracking of upgrade scripts, and automatic rejection of conflicting scripts
Modified: trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/002.schema.config.sql 2011-04-27 12:26:25 UTC (rev 20340)
+++ trunk/Open-ILS/src/sql/Pg/002.schema.config.sql 2011-04-27 15:24:54 UTC (rev 20341)
@@ -57,7 +57,7 @@
install_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
);
-INSERT INTO config.upgrade_log (version) VALUES ('0524'); -- phasefx
+INSERT INTO config.upgrade_log (version) VALUES ('0526'); -- phasefx
CREATE TABLE config.bib_source (
id SERIAL PRIMARY KEY,
Added: trunk/Open-ILS/src/sql/Pg/upgrade/0526.schema.upgrade-dep-tracking.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/upgrade/0526.schema.upgrade-dep-tracking.sql (rev 0)
+++ trunk/Open-ILS/src/sql/Pg/upgrade/0526.schema.upgrade-dep-tracking.sql 2011-04-27 15:24:54 UTC (rev 20341)
@@ -0,0 +1,79 @@
+BEGIN;
+
+INSERT INTO config.upgrade_log (version) VALUES ('0526'); --miker
+
+CREATE TABLE config.db_patch_dependencies (
+ db_patch TEXT PRIMARY KEY,
+ supersedes TEXT[],
+ deprecates TEXT[],
+ EXCLUDE ( supersedes WITH &&, deprecates WITH && )
+);
+
+ALTER TABLE config.upgrade_log
+ ADD COLUMN applied_to 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 $$
+ 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 = my_db_patch
+$$ 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 $$
+ 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 = my_db_patch
+$$ LANGUAGE SQL;
+
+-- List applied db patches that deprecates (and block the application of) my_db_patch
+CREATE OR REPLACE FUNCTION evergreen.upgrade_list_applied_superseded ( my_db_patch TEXT ) RETURNS TEXT AS $$
+ SELECT db_patch
+ FROM config.db_patch_dependencies
+ WHERE my_db_patch::TEXT[] && deprecates
+$$ LANGUAGE SQL;
+
+-- List applied db patches that supersedes (and block the application of) my_db_patch
+CREATE OR REPLACE FUNCTION evergreen.upgrade_list_applied_superseded ( my_db_patch TEXT ) RETURNS TEXT AS $$
+ SELECT db_patch
+ FROM config.db_patch_dependencies
+ WHERE my_db_patch::TEXT[] && supersedes
+$$ LANGUAGE SQL;
+
+-- Make sure that no deprecated or superseded db patches are currently applied
+CREATE OR REPLACE FUNCTION evergreen.upgrade_verify_no_dep_conflicts ( my_db_patch TEXT ) RETURNS BOOL AS $$
+ SELECT COUNT(*) = 0
+ FROM (SELECT * FROM evergreen.upgrade_list_applied_deprecates( my_db_patch )
+ UNION
+ SELECT * FROM evergreen.upgrade_list_applied_supersedes( my_db_patch )
+ UNION
+ SELECT * FROM evergreen.upgrade_list_applied_deprecated( my_db_patch )
+ UNION
+ SELECT * FROM evergreen.upgrade_list_applied_superseded( my_db_patch ))x
+$$ 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 $$
+BEGIN
+ IF NOT evergreen.upgrade_verify_no_dep_conflicts( my_db_patch ) THEN
+ RAISE EXCEPTION '
+Upgrade script % can not be applied:
+ applied deprecated scripts %
+ applied superseded scripts %
+ deprecated by %
+ superseded by %',
+ my_db_patch,
+ ARRAY_ACUM(evergreen.upgrade_list_applied_deprecates(my_db_patch)),
+ ARRAY_ACUM(evergreen.upgrade_list_applied_supersedes(my_db_patch)),
+ evergreen.upgrade_list_applied_deprecated(my_db_patch),
+ evergreen.upgrade_list_applied_superseded(my_db_patch);
+ END IF;
+
+ INSERT INTO config.upgrade_log (version, applied_to) VALUES (my_db_patch, my_applied_to);
+ RETURN TRUE;
+END;
+$$ LANGUAGE SQL;
+
+COMMIT;
More information about the open-ils-commits
mailing list