Run migrations

This commit is contained in:
Greg Shuflin 2025-02-02 19:24:45 -08:00
parent 5c295d09df
commit 239d7dd94a
3 changed files with 14 additions and 0 deletions

1
Cargo.lock generated
View File

@ -2673,6 +2673,7 @@ dependencies = [
"rocket_dyn_templates",
"rss",
"sqlx",
"tokio",
"url",
"uuid",
]

View File

@ -18,3 +18,4 @@ bcrypt = "0.15"
url = { version = "2.5", features = ["serde"] }
feed-rs = "2.3.1"
reqwest = { version = "0.12.12", features = ["json"] }
tokio = "1.43.0"

View File

@ -46,6 +46,18 @@ fn login() -> Template {
fn rocket() -> _ {
let args = Args::parse();
let db_url = format!("sqlite:{}", args.database);
// Run migrations before starting the server
let rt = tokio::runtime::Runtime::new().unwrap();
rt.block_on(async {
let pool = sqlx::SqlitePool::connect(&db_url).await.unwrap();
sqlx::migrate!("./migrations")
.run(&pool)
.await
.expect("Failed to run database migrations");
});
let figment = rocket::Config::figment().merge((
"databases.rss_data.url",
format!("sqlite:{}", args.database),