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;
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(),
}
}