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 ('0859', :eg_version); -- bshum/miker
+INSERT INTO config.upgrade_log (version, applied_to) VALUES ('0860', :eg_version); -- berick/miker
CREATE TABLE config.bib_source (
id SERIAL PRIMARY KEY,
--- /dev/null
+BEGIN;
+
+-- oh, the irony
+SELECT evergreen.upgrade_deps_block_check('0860', :eg_version);
+
+CREATE OR REPLACE FUNCTION evergreen.array_overlap_check (/* field */) RETURNS TRIGGER AS $$
+DECLARE
+ fld TEXT;
+ cnt INT;
+BEGIN
+ fld := TG_ARGV[0];
+ 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 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 = ANY(d.deprecates))
+ 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 evergreen.patch AS $$
+ SELECT DISTINCT l.version
+ FROM config.upgrade_log l
+ JOIN config.db_patch_dependencies d ON (l.version = ANY(d.supersedes))
+ WHERE d.db_patch = $1
+$$ LANGUAGE SQL;
+
+
+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 %
+ applied superseded scripts %
+ deprecated by %
+ superseded by %',
+ my_db_patch,
+ (SELECT ARRAY_AGG(patch) FROM evergreen.upgrade_list_applied_deprecates(my_db_patch)),
+ (SELECT ARRAY_AGG(patch) FROM 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 PLPGSQL;
+
+COMMIT;
+
+++ /dev/null
-
-CREATE OR REPLACE FUNCTION evergreen.array_overlap_check (/* field */) RETURNS TRIGGER AS $$
-DECLARE
- fld TEXT;
- cnt INT;
-BEGIN
- fld := TG_ARGV[0];
- 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 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 = ANY(d.deprecates))
- 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 evergreen.patch AS $$
- SELECT DISTINCT l.version
- FROM config.upgrade_log l
- JOIN config.db_patch_dependencies d ON (l.version = ANY(d.supersedes))
- WHERE d.db_patch = $1
-$$ LANGUAGE SQL;
-
-
-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 %
- applied superseded scripts %
- deprecated by %
- superseded by %',
- my_db_patch,
- (SELECT ARRAY_AGG(patch) FROM evergreen.upgrade_list_applied_deprecates(my_db_patch)),
- (SELECT ARRAY_AGG(patch) FROM 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 PLPGSQL;
-