rhythm-backend/src/database.rs
Dmitri e4c582dabe
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 9m41s
initial db interactions
2026-04-27 23:05:27 +02:00

20 lines
529 B
Rust

use sqlx::{Pool, Postgres, migrate::MigrateError, postgres::PgPoolOptions};
use crate::errors::AppError;
pub async fn init(db_url: &str) -> Result<Pool<Postgres>, AppError> {
let db = PgPoolOptions::new()
.connect(db_url)
.await
.map_err(AppError::DbConnect)?;
sqlx::migrate!("./migrations")
.run(&db)
.await
.map_err(|e: MigrateError| AppError::InvalidConfig(format!("Migration failed: {}", e)))?;
tracing::info!("Migration completed successfully");
Ok(db)
}