cat_gateway/db/event/schema_check/
mod.rsuse crate::db::event::{EventDB, DATABASE_SCHEMA_VERSION};
#[derive(thiserror::Error, Debug, PartialEq, Eq)]
#[error(" Schema in database does not match schema supported by the Crate. The current schema version: {was}, the schema version we expected: {expected}")]
pub(crate) struct MismatchedSchemaError {
was: i32,
expected: i32,
}
const SELECT_MAX_VERSION_SQL: &str = include_str!("select_max_version.sql");
impl EventDB {
pub(crate) async fn schema_version_check() -> anyhow::Result<i32> {
let schema_check = Self::query_one(SELECT_MAX_VERSION_SQL, &[]).await?;
let current_ver = schema_check.try_get("max")?;
if current_ver == DATABASE_SCHEMA_VERSION {
Ok(current_ver)
} else {
Err(MismatchedSchemaError {
was: current_ver,
expected: DATABASE_SCHEMA_VERSION,
}
.into())
}
}
}