LP#1206936 Stamping upgrade script; adding test
authorDan Wells <dbw2@calvin.edu>
Wed, 24 Feb 2016 19:27:15 +0000 (14:27 -0500)
committerDan Wells <dbw2@calvin.edu>
Wed, 24 Feb 2016 19:27:15 +0000 (14:27 -0500)
Signed-off-by: Dan Wells <dbw2@calvin.edu>
Open-ILS/src/sql/Pg/002.schema.config.sql
Open-ILS/src/sql/Pg/live_t/0959.schema.correct_mtbs_view.pg [new file with mode: 0644]
Open-ILS/src/sql/Pg/upgrade/0959.schema.correct_mtbs_view.sql [new file with mode: 0644]
Open-ILS/src/sql/Pg/upgrade/XXXX.schema.correct_mtbs_view.sql [deleted file]

index a4f3851..7f19216 100644 (file)
@@ -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 (file)
index 0000000..65f5031
--- /dev/null
@@ -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 (file)
index 0000000..f2b6e53
--- /dev/null
@@ -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 (file)
index c45b3c6..0000000
+++ /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;