diff --git a/src/config.rs b/src/config.rs index c795ed5..04904a1 100644 --- a/src/config.rs +++ b/src/config.rs @@ -41,6 +41,7 @@ pub struct Hook { pub struct Config { pub secret: String, pub base_url: String, + pub sqlite_db_path: String, pub socket_address: SocketAddress, pub email_server: EmailServer, pub email_from: Address, diff --git a/src/db.rs b/src/db.rs index b11005a..70528e1 100644 --- a/src/db.rs +++ b/src/db.rs @@ -6,7 +6,6 @@ use diesel::{ sqlite::Sqlite, }; use diesel_migrations::{embed_migrations, EmbeddedMigrations, MigrationHarness}; -use std::env; use tracing::error; use crate::{ @@ -28,12 +27,8 @@ pub fn run_migrations(connection: &mut impl MigrationHarness) -> Result< } } -pub fn establish_connection_pool() -> Result { - let database_url_var = "DATABASE_URL"; - let database_url = env::var(database_url_var) - .with_context(|| format!("Environment variable {database_url_var} missing!"))?; - - let manager = DBConnectionManager::new(database_url); +pub fn establish_connection_pool(sqlite_db_path: &str) -> Result { + let manager = DBConnectionManager::new(sqlite_db_path); Pool::builder() .build(manager) diff --git a/src/states.rs b/src/states.rs index 92d0abd..7f0489e 100644 --- a/src/states.rs +++ b/src/states.rs @@ -9,9 +9,9 @@ pub struct DB { } impl DB { - pub fn build() -> Result { + pub fn build(sqlite_db_path: &str) -> Result { Ok(Self { - pool: db::establish_connection_pool()?, + pool: db::establish_connection_pool(sqlite_db_path)?, }) } } @@ -47,10 +47,12 @@ pub struct AppState { impl AppState { pub fn build(config: config::Config, mailer: Mailer) -> Result { + let sqlite_db_path = config.sqlite_db_path.clone(); + Ok(Self { config: Arc::new(StateConfig::from(config)), mailer: Arc::new(mailer), - db: Arc::new(DB::build()?), + db: Arc::new(DB::build(&sqlite_db_path)?), }) } }