rhythm-backend/src/database.rs
Dmitri 0f7e7994ff
Some checks failed
Build and Push Docker Image / build-and-push (push) Failing after 7m33s
started base server route
2026-04-24 21:45:31 +02:00

23 lines
576 B
Rust

use std::process::exit;
use sqlx::{Pool, Postgres, postgres::PgPoolOptions};
pub async fn init(db_url: &str) -> Pool<Postgres> {
let db = match PgPoolOptions::new().connect(db_url).await {
Ok(p) => p,
Err(_) => {
tracing::error!("Failed to connect to the database");
exit(1);
}
};
match sqlx::migrate!().run(&db).await {
Ok(_) => tracing::info!("Migration completed succesfully"),
Err(_) => {
tracing::error!("Failed to apply migrations");
exit(1)
}
}
db
}