diff options
Diffstat (limited to 'lib/warden-core/src/state')
| -rw-r--r-- | lib/warden-core/src/state/database.rs | 2 | ||||
| -rw-r--r-- | lib/warden-core/src/state/mod.rs | 4 |
2 files changed, 5 insertions, 1 deletions
diff --git a/lib/warden-core/src/state/database.rs b/lib/warden-core/src/state/database.rs index cf34484..4167424 100644 --- a/lib/warden-core/src/state/database.rs +++ b/lib/warden-core/src/state/database.rs @@ -3,7 +3,7 @@ use tracing::{debug, error}; use crate::{WardenError, config::cli::database::Database}; -pub async fn connect(config: &Database) -> Result<PgPool, WardenError> { +pub(crate) async fn connect(config: &Database) -> Result<PgPool, WardenError> { let url = config.get_url()?; let host = url.host_str(); debug!(host = host, "connecting to database"); diff --git a/lib/warden-core/src/state/mod.rs b/lib/warden-core/src/state/mod.rs index f4692c2..18e44b8 100644 --- a/lib/warden-core/src/state/mod.rs +++ b/lib/warden-core/src/state/mod.rs @@ -1,5 +1,6 @@ pub(crate) mod database; use sqlx::PgPool; +use tracing::{debug, trace}; use tracing_subscriber::EnvFilter; use crate::{WardenError, config::Configuration}; @@ -15,6 +16,9 @@ pub struct AppState { impl AppState { pub async fn new(log_handle: LogHandle, config: &Configuration) -> Result<Self, WardenError> { 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, |
