athena_rs 3.18.0

Hyper performant polyglot Database driver
Documentation
//! Final report-output metadata assembly facade for `/debug/schema`.
//!
//! This module preserves a stable metadata-assembly import surface while
//! staged metadata stage-input payload assembly is delegated to
//! `debug_report_output_metadata_stage_input_assembly`, staged metadata payload
//! assembly is delegated to
//! `debug_report_output_metadata_stage_output_assembly` and final metadata
//! handoff is delegated to the stable facade in
//! `debug_report_output_metadata_from_stage_output_assembly`, which delegates to
//! `debug_report_output_metadata_stage_output_handoff_assembly`, which
//! delegates contract projection to
//! `debug_report_output_metadata_stage_output_contract_handoff_assembly`.

use super::debug_observed_tables::LoggingSchemaObservedTable;
use super::debug_report_output_metadata_contracts::LoggingSchemaDebugReportOutputMetadata;
use super::debug_report_output_metadata_from_stage_output_assembly::build_logging_schema_debug_report_output_metadata_from_stage_output_assembly;
use super::debug_report_output_metadata_stage_input_assembly::build_debug_report_output_metadata_stage_input_assembly;
use super::debug_report_output_metadata_stage_output_assembly::build_debug_report_output_metadata_stage_output_assembly;
use super::debug_still_needed::LoggingSchemaDebugStillNeeded;

/// Builds final report metadata and legacy compatibility fields.
pub(super) fn build_logging_schema_debug_report_output_metadata(
    still_needed: &LoggingSchemaDebugStillNeeded,
    observed_tables: Vec<LoggingSchemaObservedTable>,
) -> LoggingSchemaDebugReportOutputMetadata {
    let stage_input =
        build_debug_report_output_metadata_stage_input_assembly(still_needed, observed_tables);
    let stage = build_debug_report_output_metadata_stage_output_assembly(stage_input);
    build_logging_schema_debug_report_output_metadata_from_stage_output_assembly(stage)
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::api::schema::debug_report_output_metadata_test_fixtures::build_metadata_stage_input_parts_for_tests;

    #[test]
    /// Preserves observed rows and still-needed table keys in final metadata output.
    fn metadata_assembly_preserves_observed_rows_and_legacy_missing_table_keys() {
        let (still_needed, observed_tables) = build_metadata_stage_input_parts_for_tests();

        let metadata =
            build_logging_schema_debug_report_output_metadata(&still_needed, observed_tables);

        assert_eq!(metadata.observed_tables.len(), 1);
        assert_eq!(
            metadata.missing_required_tables,
            vec!["public.gateway_request_log".to_string()]
        );
        assert_eq!(
            metadata.missing_optional_tables,
            vec!["public.route_request_log".to_string()]
        );
        assert!(metadata.generated_at.timestamp() > 0);
    }
}