Skip to main content

gaman_core/runner/
adapters.rs

1use thiserror::Error;
2
3use crate::migration_engine::{BoxFuture, ExecutorError};
4use crate::states::Schema;
5/// Reflects high-fidelity schema state from a live target without defining drift policy.
6pub trait SchemaInspector: Send {
7    /// Reads requested namespaces from the target database.
8    fn inspect<'a>(
9        &'a mut self,
10        schemas: &'a [&'a str],
11    ) -> BoxFuture<'a, Result<Schema, InspectionError>>;
12}
13
14impl<T> SchemaInspector for &mut T
15where
16    T: SchemaInspector + ?Sized,
17{
18    fn inspect<'a>(
19        &'a mut self,
20        schemas: &'a [&'a str],
21    ) -> BoxFuture<'a, Result<Schema, InspectionError>> {
22        (**self).inspect(schemas)
23    }
24}
25
26/// Failure returned by a host-provided schema inspector.
27#[derive(Debug, Error)]
28pub enum InspectionError {
29    /// The selected host cannot inspect live catalog state.
30    #[error("inspection is unavailable for {dialect}")]
31    Unavailable { dialect: String },
32    /// A catalog query or interpretation step failed.
33    #[error("database inspection failed: {message}")]
34    Query { message: String },
35    /// Reflected catalog state violated a required schema invariant.
36    #[error("invalid inspected catalog state: {message}")]
37    InvalidCatalogState { message: String },
38}
39
40impl InspectionError {
41    /// Creates a catalog-query failure from host adapter context.
42    pub fn query(message: impl Into<String>) -> Self {
43        Self::Query {
44            message: message.into(),
45        }
46    }
47}
48
49impl From<ExecutorError> for InspectionError {
50    /// Converts a catalog adapter failure into the runner's inspection boundary error.
51    fn from(error: ExecutorError) -> Self {
52        Self::Query {
53            message: error.to_string(),
54        }
55    }
56}