mirror of
https://codeberg.org/Mo8it/git-webhook-client
synced 2024-11-23 11:11:36 +00:00
Add sqlite_db_path
This commit is contained in:
parent
539c15e221
commit
3baa503fbf
3 changed files with 8 additions and 10 deletions
|
@ -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,
|
||||
|
|
|
@ -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<Sqlite>) -> Result<
|
|||
}
|
||||
}
|
||||
|
||||
pub fn establish_connection_pool() -> Result<DBPool> {
|
||||
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<DBPool> {
|
||||
let manager = DBConnectionManager::new(sqlite_db_path);
|
||||
|
||||
Pool::builder()
|
||||
.build(manager)
|
||||
|
|
|
@ -9,9 +9,9 @@ pub struct DB {
|
|||
}
|
||||
|
||||
impl DB {
|
||||
pub fn build() -> Result<Self> {
|
||||
pub fn build(sqlite_db_path: &str) -> Result<Self> {
|
||||
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<Self> {
|
||||
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)?),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue