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,
--- /dev/null
+\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;
--- /dev/null
+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;
+++ /dev/null
-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;