-- Rollback draft for migration 004; restores the pre-002 view column list.
-- Target database: booking_test.

BEGIN;

CREATE OR REPLACE VIEW finance.v_active_daily_facts AS
SELECT
    records.id,
    records.daily_version_id,
    records.source_sequence,
    records.source_location,
    records.outcome,
    records.decision_codes,
    records.duplicate_of_record_id,
    records.block_code,
    records.group_code_key,
    records.adults,
    records.children,
    records.company_name,
    records.company_key,
    records.confirmation_no,
    records.disp_room_no,
    records.effective_rate_amount,
    records.full_name,
    records.res_comment,
    records.trace_text,
    records.no_of_rooms,
    records.products,
    records.rate_code,
    records.normalized_rate_code,
    records.room_category_label,
    records.arrival,
    records.departure,
    records.nights,
    records.real_price,
    records.total_price,
    records.kb_amount,
    records.channel_key,
    records.pricing_method,
    records.booking_parse_version_id,
    records.booking_match_status,
    records.created_at
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
  'Only retained rows from each business date current active daily version.';

COMMIT;
