added settings crate, creating settings on web startup
This commit is contained in:
parent
9c2b43ec3c
commit
a85c1431c8
7 changed files with 148 additions and 7 deletions
|
|
@ -10,4 +10,5 @@ rocket_dyn_templates = { version = "0.1.0-rc.2", features = ["tera"] }
|
|||
infer = { version = "0.12.0", default-features = false }
|
||||
|
||||
# local crates
|
||||
database_pool = { path = "../database_pool" }
|
||||
database_pool = { path = "../database_pool" }
|
||||
settings = { path = "../settings" }
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ use database_pool::run_migrations;
|
|||
use rocket::fairing::AdHoc;
|
||||
use rocket::{error, fairing, info, Build, Rocket};
|
||||
use rocket_db_pools::{sqlx, Database as RocketDatabase};
|
||||
use settings::Settings;
|
||||
|
||||
#[derive(RocketDatabase)]
|
||||
#[database("ezidam")]
|
||||
|
|
@ -25,10 +26,26 @@ impl Database {
|
|||
match run_migrations(&db.0).await {
|
||||
Ok(()) => {
|
||||
info!("Migrations ran successfully");
|
||||
Ok(rocket)
|
||||
}
|
||||
Err(e) => {
|
||||
error!("Failed to run migrations: {}", e);
|
||||
return Err(rocket);
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize settings
|
||||
match Settings::init(&db.0).await {
|
||||
Ok(insertion) => {
|
||||
if insertion.is_some() {
|
||||
// This should happen only once in the lifetime of the database
|
||||
info!("Created settings in database");
|
||||
} else {
|
||||
info!("Found existing settings in database");
|
||||
}
|
||||
Ok(rocket)
|
||||
}
|
||||
Err(e) => {
|
||||
error!("Failed to interact with settings: {}", e);
|
||||
Err(rocket)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue