pub(crate) mod database; use sqlx::PgPool; use tracing::{debug, trace}; use tracing_subscriber::EnvFilter; use crate::{WardenError, config::Configuration}; pub type LogHandle = tracing_subscriber::reload::Handle; #[derive(Debug, Clone)] pub struct AppState { pub log_handle: LogHandle, pub database: PgPool, } impl AppState { pub async fn new(log_handle: LogHandle, config: &Configuration) -> Result { let database = database::connect(&config.database).await?; trace!("running database migrations"); sqlx::migrate!("../../migrations").run(&database).await?; debug!("database up to date"); Ok(Self { log_handle, database, }) } }