Files
wyndham-ARR/database/004_refresh_active_daily_facts_view.sql
2026-07-29 16:38:05 +08:00

18 lines
613 B
PL/PgSQL

-- Refresh the records.* expansion after migration 002 added Finance source-link columns.
-- PostgreSQL 15+
-- Target database: booking_test.
BEGIN;
CREATE OR REPLACE VIEW finance.v_active_daily_facts AS
SELECT records.*
FROM finance.current_daily_versions AS current_version
JOIN finance.daily_records AS records
ON records.daily_version_id = current_version.daily_version_id
WHERE records.outcome = 'retained';
COMMENT ON VIEW finance.v_active_daily_facts IS
'All columns from retained rows in each business date current active daily version, refreshed after schema migrations add row fields.';
COMMIT;