gaman_core/runner/
adapters.rs1use thiserror::Error;
2
3use crate::migration_engine::{BoxFuture, ExecutorError};
4use crate::states::Schema;
5pub trait SchemaInspector: Send {
7 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#[derive(Debug, Error)]
28pub enum InspectionError {
29 #[error("inspection is unavailable for {dialect}")]
31 Unavailable { dialect: String },
32 #[error("database inspection failed: {message}")]
34 Query { message: String },
35 #[error("invalid inspected catalog state: {message}")]
37 InvalidCatalogState { message: String },
38}
39
40impl InspectionError {
41 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 fn from(error: ExecutorError) -> Self {
52 Self::Query {
53 message: error.to_string(),
54 }
55 }
56}