athena_rs 3.26.3

Hyper performant polyglot Database driver
//! Final snapshot payload assembly for `/debug/schema`.
//!
//! This module owns constructing `LoggingSchemaSnapshot` from raw relation and
//! column query rows.

use super::debug_snapshot_contracts::{LoggingSchemaSnapshot, LoggingSchemaSnapshotRows};

/// Builds one in-memory logging-schema snapshot from raw catalog query rows.
pub(super) fn build_logging_schema_snapshot_output(
    rows: LoggingSchemaSnapshotRows,
) -> LoggingSchemaSnapshot {
    LoggingSchemaSnapshot {
        relations: rows.relations,
        columns: rows.columns,
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::api::schema::service::{SchemaColumnRecord, SchemaRelationRecord};

    #[test]
    /// Preserves relation/column query rows when building snapshot payload output.
    fn snapshot_output_preserves_relation_and_column_rows() {
        let rows = LoggingSchemaSnapshotRows {
            relations: vec![SchemaRelationRecord {
                table_schema: "public".to_string(),
                table_name: "gateway_request_log".to_string(),
                relation_type: "BASE TABLE".to_string(),
            }],
            columns: vec![SchemaColumnRecord {
                table_schema: "public".to_string(),
                table_name: "gateway_request_log".to_string(),
                column_name: "request_id".to_string(),
                data_type: Some("uuid".to_string()),
                column_default: None,
                is_nullable: Some("NO".to_string()),
            }],
        };

        let snapshot = build_logging_schema_snapshot_output(rows);

        assert_eq!(snapshot.relations.len(), 1);
        assert_eq!(snapshot.columns.len(), 1);
        assert_eq!(snapshot.relations[0].table_name, "gateway_request_log");
        assert_eq!(snapshot.columns[0].column_name, "request_id");
    }
}