cleanup: remove old configuration code
This commit is contained in:
parent
dad19548d1
commit
c16b068f8b
1 changed files with 5 additions and 9 deletions
|
@ -28,11 +28,9 @@ use axum::{
|
||||||
Router,
|
Router,
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: make these configurable
|
|
||||||
const SIMPLEBOT_PATH: &str = "../simplebot/simplebot.py";
|
|
||||||
|
|
||||||
type ConnectionPool = bb8::Pool<DieselConnectionManager<PgConnection>>;
|
type ConnectionPool = bb8::Pool<DieselConnectionManager<PgConnection>>;
|
||||||
|
|
||||||
|
// this should probably be modularized a bit as the config grows
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct GlobalConfig {
|
pub struct GlobalConfig {
|
||||||
/// url for the postgres database
|
/// url for the postgres database
|
||||||
|
@ -59,6 +57,9 @@ pub struct GlobalConfig {
|
||||||
pub registry_admin_password: String,
|
pub registry_admin_password: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: do we still need this? Is there a better way?
|
||||||
|
const SIMPLEBOT_PATH: &str = "../simplebot/simplebot.py";
|
||||||
|
|
||||||
pub async fn seed_simplebot(config: &GlobalConfig, pool: &ConnectionPool) {
|
pub async fn seed_simplebot(config: &GlobalConfig, pool: &ConnectionPool) {
|
||||||
let conn = pool.get().await.expect("could not get database connection");
|
let conn = pool.get().await.expect("could not get database connection");
|
||||||
// This transaction is expected to fail when simplebot already exists.
|
// This transaction is expected to fail when simplebot already exists.
|
||||||
|
@ -88,7 +89,7 @@ pub type DbPool = Pool<DieselConnectionManager<PgConnection>>;
|
||||||
pub async fn prepare_db(config: &GlobalConfig) -> DbPool {
|
pub async fn prepare_db(config: &GlobalConfig) -> DbPool {
|
||||||
let manager = DieselConnectionManager::<PgConnection>::new(&config.database_url);
|
let manager = DieselConnectionManager::<PgConnection>::new(&config.database_url);
|
||||||
let pool = bb8::Pool::builder().build(manager).await.unwrap();
|
let pool = bb8::Pool::builder().build(manager).await.unwrap();
|
||||||
seed_simplebot(&config, &pool).await;
|
seed_simplebot(config, &pool).await;
|
||||||
pool
|
pool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,11 +161,6 @@ pub async fn run_app() {
|
||||||
axum::Server::bind(&addr).serve(api_service).await.unwrap();
|
axum::Server::bind(&addr).serve(api_service).await.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
|
||||||
pub struct Configuration {
|
|
||||||
pub database_url: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
// we can also write a custom extractor that grabs a connection from the pool
|
// we can also write a custom extractor that grabs a connection from the pool
|
||||||
// which setup is appropriate depends on your application
|
// which setup is appropriate depends on your application
|
||||||
pub struct DatabaseConnection(PooledConnection<'static, DieselConnectionManager<PgConnection>>);
|
pub struct DatabaseConnection(PooledConnection<'static, DieselConnectionManager<PgConnection>>);
|
||||||
|
|
Loading…
Reference in a new issue