aboutsummaryrefslogtreecommitdiffstats
path: root/lib/warden-core
diff options
context:
space:
mode:
Diffstat (limited to 'lib/warden-core')
-rw-r--r--lib/warden-core/src/error.rs2
-rw-r--r--lib/warden-core/src/state/database.rs2
-rw-r--r--lib/warden-core/src/state/mod.rs4
3 files changed, 7 insertions, 1 deletions
diff --git a/lib/warden-core/src/error.rs b/lib/warden-core/src/error.rs
index f05971f..d90a862 100644
--- a/lib/warden-core/src/error.rs
+++ b/lib/warden-core/src/error.rs
@@ -5,6 +5,8 @@ pub enum WardenError {
#[error(transparent)]
Datastore(#[from] sqlx::Error),
#[error(transparent)]
+ Migration(#[from] sqlx::migrate::MigrateError),
+ #[error(transparent)]
Url(#[from] url::ParseError),
#[error("Missing required configuration values:\n`{0}`")]
Config(String),
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,