From: Dan Wells Date: Wed, 24 Feb 2016 19:27:15 +0000 (-0500) Subject: LP#1206936 Stamping upgrade script; adding test X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=b4415faed29799de99ac901cdb852ffce9ec9748;p=evergreen%2Fmasslnc.git LP#1206936 Stamping upgrade script; adding test Signed-off-by: Dan Wells --- diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql index a4f3851b8f..7f1921638d 100644 --- a/Open-ILS/src/sql/Pg/002.schema.config.sql +++ b/Open-ILS/src/sql/Pg/002.schema.config.sql @@ -91,7 +91,7 @@ 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 ('0958', :eg_version); -- gmcharlt/bshum +INSERT INTO config.upgrade_log (version, applied_to) VALUES ('0959', :eg_version); -- csharp/dbwells CREATE TABLE config.bib_source ( id SERIAL PRIMARY KEY, diff --git a/Open-ILS/src/sql/Pg/live_t/0959.schema.correct_mtbs_view.pg b/Open-ILS/src/sql/Pg/live_t/0959.schema.correct_mtbs_view.pg new file mode 100644 index 0000000000..65f50312a1 --- /dev/null +++ b/Open-ILS/src/sql/Pg/live_t/0959.schema.correct_mtbs_view.pg @@ -0,0 +1,48 @@ +\set ECHO 'none' +\set QUIET 1 +-- Turn off echo and keep things quiet. + +-- Format the output for nice TAP. +\pset format unaligned +\pset tuples_only true +\pset pager + +-- Revert all changes on failure. +\set ON_ERROR_ROLLBACK 1 +\set ON_ERROR_STOP true + +-- let's do this thing +BEGIN; + +-- putting tests in function to allow for variable reuse +CREATE OR REPLACE FUNCTION mtbs_test() RETURNS SETOF TEXT AS $$ +DECLARE + max_id bigint; +BEGIN + +RETURN QUERY SELECT plan(2); + +SELECT max(mbx.id) INTO max_id +FROM money.billable_xact mbx +JOIN money.billing mb ON NOT mb.voided AND mb.xact = mbx.id; + +RETURN QUERY SELECT is( + (SELECT DISTINCT ON (xact) billing_type FROM money.billing WHERE xact = max_id ORDER BY xact, billing_ts DESC), + (SELECT last_billing_type FROM money.transaction_billing_summary WHERE xact = max_id), + 'mtbs has correct last billing type' +); + +RETURN QUERY SELECT is( + (SELECT DISTINCT ON (xact) note FROM money.billing WHERE xact = max_id ORDER BY xact, billing_ts DESC), + (SELECT last_billing_note FROM money.transaction_billing_summary WHERE xact = max_id), + 'mtbs has correct last billing note' +); + +RETURN QUERY SELECT * FROM finish(); + +END; +$$ LANGUAGE plpgsql; + +SELECT mtbs_test(); + +ROLLBACK; diff --git a/Open-ILS/src/sql/Pg/upgrade/0959.schema.correct_mtbs_view.sql b/Open-ILS/src/sql/Pg/upgrade/0959.schema.correct_mtbs_view.sql new file mode 100644 index 0000000000..f2b6e5325b --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/0959.schema.correct_mtbs_view.sql @@ -0,0 +1,13 @@ +BEGIN; + +SELECT evergreen.upgrade_deps_block_check('0959', :eg_version); + +CREATE OR REPLACE VIEW money.transaction_billing_summary AS + SELECT id as xact, + last_billing_type, + last_billing_note, + last_billing_ts, + total_owed + FROM money.materialized_billable_xact_summary; + +COMMIT; diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.correct_mtbs_view.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.correct_mtbs_view.sql deleted file mode 100644 index c45b3c6d18..0000000000 --- a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.correct_mtbs_view.sql +++ /dev/null @@ -1,13 +0,0 @@ -BEGIN; - -SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version); - -CREATE OR REPLACE VIEW money.transaction_billing_summary AS - SELECT id as xact, - last_billing_type, - last_billing_note, - last_billing_ts, - total_owed - FROM money.materialized_billable_xact_summary; - -COMMIT;