athena_rs 3.26.4

Hyper performant polyglot Database driver
Documentation
//! Legacy missing-table field adaptation for `/debug/schema`.
//!
//! This module preserves compatibility with top-level
//! `missing_required_tables`/`missing_optional_tables` fields while using
//! `still_needed` as the canonical unresolved-requirements source.

use super::debug_legacy_missing_tables_contracts::LoggingSchemaDebugLegacyMissingTables;
use super::debug_still_needed::LoggingSchemaDebugStillNeeded;

/// Builds legacy top-level missing-table lists from canonical `still_needed`.
pub(super) fn build_logging_schema_debug_legacy_missing_tables(
    still_needed: &LoggingSchemaDebugStillNeeded,
) -> LoggingSchemaDebugLegacyMissingTables {
    LoggingSchemaDebugLegacyMissingTables {
        missing_required_tables: still_needed.required_missing_tables.clone(),
        missing_optional_tables: still_needed.optional_missing_tables.clone(),
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    /// Keeps legacy missing-table fields aligned with canonical still-needed tables.
    #[test]
    fn legacy_missing_tables_are_derived_from_still_needed_tables() {
        let still_needed = LoggingSchemaDebugStillNeeded {
            required_missing_tables: vec!["public.gateway_request_log".to_string()],
            optional_missing_tables: vec!["public.route_request_log".to_string()],
            required_missing_columns: vec!["public.gateway_request_log.request_id".to_string()],
            optional_missing_columns: vec!["public.route_request_log.route_path".to_string()],
            relation_type_mismatches: vec!["public.route_request_log".to_string()],
        };

        let legacy = build_logging_schema_debug_legacy_missing_tables(&still_needed);

        assert_eq!(
            legacy.missing_required_tables,
            still_needed.required_missing_tables
        );
        assert_eq!(
            legacy.missing_optional_tables,
            still_needed.optional_missing_tables
        );
    }
}