[open-ils-commits] r20351 - in trunk/Open-ILS/src/sql/Pg: . upgrade (miker)
svn at svn.open-ils.org
svn at svn.open-ils.org
Wed Apr 27 16:25:15 EDT 2011
Author: miker
Date: 2011-04-27 16:25:10 -0400 (Wed, 27 Apr 2011)
New Revision: 20351
Modified:
trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
trunk/Open-ILS/src/sql/Pg/build-db.sh
trunk/Open-ILS/src/sql/Pg/upgrade/0526.schema.upgrade-dep-tracking.sql
Log:
fix the new deps stuff
Modified: trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/002.schema.config.sql 2011-04-27 19:16:12 UTC (rev 20350)
+++ trunk/Open-ILS/src/sql/Pg/002.schema.config.sql 2011-04-27 20:25:10 UTC (rev 20351)
@@ -61,11 +61,31 @@
CREATE TABLE config.db_patch_dependencies (
db_patch TEXT PRIMARY KEY,
supersedes TEXT[],
- deprecates TEXT[],
- CONSTRAINT supersede_once EXCLUDE USING GIST ( supersedes WITH && ),
- CONSTRAINT deprecate_once EXCLUDE USING GIST ( deprecates WITH && )
+ deprecates TEXT[]
);
+CREATE OR REPLACE FUNCTION evergreen.array_overlap_check (/* field */) RETURNS TRIGGER AS $$
+DECLARE
+ fld TEXT;
+ cnt INT;
+BEGIN
+ fld := TG_ARGV[1];
+ EXECUTE 'SELECT COUNT(*) FROM '|| TG_TABLE_SCHEMA ||'.'|| TG_TABLE_NAME ||' WHERE '|| fld ||' && ($1).'|| fld INTO cnt USING NEW;
+ IF cnt > 0 THEN
+ RAISE EXCEPTION 'Cannot insert duplicate array into field % of table %', fld, TG_TABLE_SCHEMA ||'.'|| TG_TABLE_NAME;
+ END IF;
+ RETURN NEW;
+END;
+$$ LANGUAGE PLPGSQL;
+
+CREATE TRIGGER no_overlapping_sups
+ BEFORE INSERT OR UPDATE ON config.db_patch_dependencies
+ FOR EACH ROW EXECUTE PROCEDURE evergreen.array_overlap_check ('supersedes');
+
+CREATE TRIGGER no_overlapping_deps
+ BEFORE INSERT OR UPDATE ON config.db_patch_dependencies
+ FOR EACH ROW EXECUTE PROCEDURE evergreen.array_overlap_check ('deprecates');
+
INSERT INTO config.upgrade_log (version, applied_to) VALUES ('0526', :eg_version); -- miker
CREATE TABLE config.bib_source (
@@ -808,7 +828,7 @@
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
+ WHERE d.db_patch = $1
$$ LANGUAGE SQL;
-- List applied db patches that are superseded by (and block the application of) my_db_patch
@@ -816,33 +836,33 @@
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
+ WHERE d.db_patch = $1
$$ 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 $$
+CREATE OR REPLACE FUNCTION evergreen.upgrade_list_applied_deprecated ( my_db_patch TEXT ) RETURNS TEXT AS $$
SELECT db_patch
FROM config.db_patch_dependencies
- WHERE my_db_patch::TEXT[] && deprecates
+ WHERE ARRAY[$1]::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
+ WHERE ARRAY[$1]::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 )
+ FROM (SELECT * FROM evergreen.upgrade_list_applied_deprecates( $1 )
UNION
- SELECT * FROM evergreen.upgrade_list_applied_supersedes( my_db_patch )
+ SELECT * FROM evergreen.upgrade_list_applied_supersedes( $1 )
UNION
- SELECT * FROM evergreen.upgrade_list_applied_deprecated( my_db_patch )
+ SELECT * FROM evergreen.upgrade_list_applied_deprecated( $1 )
UNION
- SELECT * FROM evergreen.upgrade_list_applied_superseded( my_db_patch ))x
+ SELECT * FROM evergreen.upgrade_list_applied_superseded( $1 ))x
$$ LANGUAGE SQL;
-- Raise an exception if there are, in fact, dep/sup confilct
@@ -865,6 +885,6 @@
INSERT INTO config.upgrade_log (version, applied_to) VALUES (my_db_patch, my_applied_to);
RETURN TRUE;
END;
-$$ LANGUAGE SQL;
+$$ LANGUAGE PLPGSQL;
COMMIT;
Modified: trunk/Open-ILS/src/sql/Pg/build-db.sh
===================================================================
--- trunk/Open-ILS/src/sql/Pg/build-db.sh 2011-04-27 19:16:12 UTC (rev 20350)
+++ trunk/Open-ILS/src/sql/Pg/build-db.sh 2011-04-27 20:25:10 UTC (rev 20351)
@@ -96,9 +96,9 @@
export PGHOST PGPORT PGDATABASE PGUSER PGPASSWORD
# Hide most of the harmless messages that obscure real problems
if [ -z "$VERBOSE" ]; then
- psql -f $sql_file 2>&1 | grep -v NOTICE | grep -v "^INSERT"
+ psql -v eg_version=NULL -f $sql_file 2>&1 | grep -v NOTICE | grep -v "^INSERT"
else
- psql -f $sql_file
+ psql -v eg_version=NULL -f $sql_file
fi
if [ $? != 0 ]; then
cat <<EOM
Modified: 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 2011-04-27 19:16:12 UTC (rev 20350)
+++ trunk/Open-ILS/src/sql/Pg/upgrade/0526.schema.upgrade-dep-tracking.sql 2011-04-27 20:25:10 UTC (rev 20351)
@@ -5,11 +5,31 @@
CREATE TABLE config.db_patch_dependencies (
db_patch TEXT PRIMARY KEY,
supersedes TEXT[],
- deprecates TEXT[],
- CONSTRAINT supersede_once EXCLUDE USING GIST ( supersedes WITH && ),
- CONSTRAINT deprecate_once EXCLUDE USING GIST ( deprecates WITH && )
+ deprecates TEXT[]
);
+CREATE OR REPLACE FUNCTION evergreen.array_overlap_check (/* field */) RETURNS TRIGGER AS $$
+DECLARE
+ fld TEXT;
+ cnt INT;
+BEGIN
+ fld := TG_ARGV[1];
+ EXECUTE 'SELECT COUNT(*) FROM '|| TG_TABLE_SCHEMA ||'.'|| TG_TABLE_NAME ||' WHERE '|| fld ||' && ($1).'|| fld INTO cnt USING NEW;
+ IF cnt > 0 THEN
+ RAISE EXCEPTION 'Cannot insert duplicate array into field % of table %', fld, TG_TABLE_SCHEMA ||'.'|| TG_TABLE_NAME;
+ END IF;
+ RETURN NEW;
+END;
+$$ LANGUAGE PLPGSQL;
+
+CREATE TRIGGER no_overlapping_sups
+ BEFORE INSERT OR UPDATE ON config.db_patch_dependencies
+ FOR EACH ROW EXECUTE PROCEDURE evergreen.array_overlap_check ('supersedes');
+
+CREATE TRIGGER no_overlapping_deps
+ BEFORE INSERT OR UPDATE ON config.db_patch_dependencies
+ FOR EACH ROW EXECUTE PROCEDURE evergreen.array_overlap_check ('deprecates');
+
ALTER TABLE config.upgrade_log
ADD COLUMN applied_to TEXT;
@@ -18,7 +38,7 @@
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
+ WHERE d.db_patch = $1
$$ LANGUAGE SQL;
-- List applied db patches that are superseded by (and block the application of) my_db_patch
@@ -26,33 +46,33 @@
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
+ WHERE d.db_patch = $1
$$ 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 $$
+CREATE OR REPLACE FUNCTION evergreen.upgrade_list_applied_deprecated ( my_db_patch TEXT ) RETURNS TEXT AS $$
SELECT db_patch
FROM config.db_patch_dependencies
- WHERE my_db_patch::TEXT[] && deprecates
+ WHERE ARRAY[$1]::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
+ WHERE ARRAY[$1]::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 )
+ FROM (SELECT * FROM evergreen.upgrade_list_applied_deprecates( $1 )
UNION
- SELECT * FROM evergreen.upgrade_list_applied_supersedes( my_db_patch )
+ SELECT * FROM evergreen.upgrade_list_applied_supersedes( $1 )
UNION
- SELECT * FROM evergreen.upgrade_list_applied_deprecated( my_db_patch )
+ SELECT * FROM evergreen.upgrade_list_applied_deprecated( $1 )
UNION
- SELECT * FROM evergreen.upgrade_list_applied_superseded( my_db_patch ))x
+ SELECT * FROM evergreen.upgrade_list_applied_superseded( $1 ))x
$$ LANGUAGE SQL;
-- Raise an exception if there are, in fact, dep/sup confilct
@@ -75,6 +95,6 @@
INSERT INTO config.upgrade_log (version, applied_to) VALUES (my_db_patch, my_applied_to);
RETURN TRUE;
END;
-$$ LANGUAGE SQL;
+$$ LANGUAGE PLPGSQL;
COMMIT;
More information about the open-ils-commits
mailing list