use sqlx::{Pool, Postgres, migrate::MigrateError, postgres::PgPoolOptions}; use crate::errors::AppError; pub async fn init(db_url: &str) -> Result, 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) }