cat_gateway/db/event/schema_check/
mod.rs1use crate::db::event::{EventDB, DATABASE_SCHEMA_VERSION};
4
5#[derive(thiserror::Error, Debug, PartialEq, Eq)]
7#[error(" Schema in database does not match schema supported by the Crate. The current schema version: {was}, the schema version we expected: {expected}")]
8pub(crate) struct MismatchedSchemaError {
9 was: i32,
11 expected: i32,
13}
14
15const SELECT_MAX_VERSION_SQL: &str = include_str!("select_max_version.sql");
17
18impl EventDB {
19 pub(crate) async fn schema_version_check() -> anyhow::Result<i32> {
23 let schema_check = Self::query_one(SELECT_MAX_VERSION_SQL, &[]).await?;
24
25 let current_ver = schema_check.try_get("max")?;
26
27 if current_ver == DATABASE_SCHEMA_VERSION {
28 Ok(current_ver)
29 } else {
30 Err(MismatchedSchemaError {
31 was: current_ver,
32 expected: DATABASE_SCHEMA_VERSION,
33 }
34 .into())
35 }
36 }
37}