aboutsummaryrefslogtreecommitdiffstats
path: root/lib/warden-core/src
diff options
context:
space:
mode:
authorrtkay123 <dev@kanjala.com>2026-03-29 21:12:32 +0200
committerrtkay123 <dev@kanjala.com>2026-03-29 21:12:32 +0200
commit747a594a8010d6ba5dc97a583335aba2fb35392a (patch)
tree63158cb4f601a95af6142676457d185f35d5fb90 /lib/warden-core/src
parent51a5e45707a4c0a229ad35ef48f23b3e88de6323 (diff)
downloadwarden-747a594a8010d6ba5dc97a583335aba2fb35392a.tar.bz2
warden-747a594a8010d6ba5dc97a583335aba2fb35392a.zip
feat(schema): get schema
Diffstat (limited to 'lib/warden-core/src')
-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,