systemprompt_runtime/
validation.rs1use crate::AppContext;
4use crate::error::{RuntimeError, RuntimeResult};
5use std::path::Path;
6use systemprompt_database::validate_database_connection;
7
8pub async fn validate_system(ctx: &AppContext) -> RuntimeResult<()> {
9 validate_database(ctx).await
10}
11
12async fn validate_database(ctx: &AppContext) -> RuntimeResult<()> {
13 validate_database_path(&ctx.config().database_url)?;
14 validate_database_connection(ctx.db_pool().as_ref()).await?;
15 Ok(())
16}
17
18pub fn validate_database_path(db_path: &str) -> RuntimeResult<()> {
19 if db_path.is_empty() {
20 return Err(RuntimeError::EmptyDatabaseUrl);
21 }
22
23 if db_path.starts_with("postgresql://") || db_path.starts_with("postgres://") {
24 return Ok(());
25 }
26
27 let path = Path::new(db_path);
28
29 if !path.exists() {
30 return Err(RuntimeError::DatabaseNotFound {
31 path: db_path.to_string(),
32 });
33 }
34
35 if !path.is_file() {
36 return Err(RuntimeError::DatabaseNotFile {
37 path: db_path.to_string(),
38 });
39 }
40
41 Ok(())
42}