3 INSERT INTO config.upgrade_log (version, install_date) VALUES ('XXXXXXX',now());
5 -- acq.fund_combined_balance is unchanged however we need to drop it to recreate the other views
6 -- we need to drop all our views because we change the number of columns
7 -- for example, debit_total does not need an encumberance column when we have a sepearate total for that
9 DROP VIEW acq.fund_combined_balance;
10 DROP VIEW acq.fund_encumbrance_total;
11 DROP VIEW acq.fund_spent_total;
12 DROP VIEW acq.fund_debit_total;
14 CREATE OR REPLACE VIEW acq.fund_debit_total AS
15 SELECT fund.id AS fund, sum(COALESCE(fund_debit.amount, 0::numeric)) AS amount
17 LEFT JOIN acq.fund_debit fund_debit ON fund.id = fund_debit.fund
20 CREATE OR REPLACE VIEW acq.fund_encumbrance_total AS
21 SELECT fund.id AS fund, sum(COALESCE(fund_debit.amount, 0::numeric)) AS amount FROM acq.fund fund
22 LEFT JOIN acq.fund_debit fund_debit ON fund.id = fund_debit.fund WHERE fund_debit.encumbrance GROUP BY fund.id;
24 CREATE OR REPLACE VIEW acq.fund_spent_total AS
25 SELECT fund.id AS fund, sum(COALESCE(fund_debit.amount, 0::numeric)) AS amount FROM acq.fund fund
26 LEFT JOIN acq.fund_debit fund_debit ON fund.id = fund_debit.fund WHERE NOT fund_debit.encumbrance GROUP BY fund.id;
28 CREATE OR REPLACE VIEW acq.fund_combined_balance AS
29 SELECT c.fund, c.amount - COALESCE(d.amount, 0.0) AS amount
30 FROM acq.fund_allocation_total c
31 LEFT JOIN acq.fund_debit_total d USING (fund);