athena_rs 3.26.3

Hyper performant polyglot Database driver
//! `/schema/migrations` response orchestration.
//!
//! This module isolates migration-specific response handling so catalog
//! response helpers for other endpoints remain focused on shared flows.

use actix_web::HttpResponse;
use serde_json::json;
use sqlx::{Pool, Postgres};

use super::catalog_migration_error_mapper::{
    schema_migrations_compatibility_response, schema_migrations_fetch_error,
};
use super::catalog_migration_loader::load_schema_migration_rows;
use super::schema_backend::SchemaBackend;

/// Builds a `/schema/migrations` response for the resolved schema client pool.
pub(super) async fn schema_migrations_response(
    backend: &SchemaBackend,
    _app_state: &crate::AppState,
) -> HttpResponse {
    match backend {
        SchemaBackend::Postgres { pool } => match load_schema_migration_rows(pool).await {
            Ok(migrations) => HttpResponse::Ok().json(json!({ "migrations": migrations })),
            Err(err) => schema_migrations_fetch_error(err),
        },
        SchemaBackend::D1 { .. } => schema_migrations_compatibility_response(),
    }
}