The backend had never been run through rustfmt. Doing it in one mechanical pass (134 files) so no future functional diff is buried under formatting churn, then gating `cargo fmt --check` in checks.yml so it stays clean. Formatting only — no logic, SQL, or behaviour changed. Verified after the reformat: cargo test 56 passed, clippy --all-targets -D warnings clean, cargo fmt --check clean. This is the deferred cleanup noted when CI's Format step was first left out. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
27 lines
752 B
Rust
27 lines
752 B
Rust
use anyhow::{Context, Result};
|
|
use sqlx::PgPool;
|
|
use sqlx::postgres::PgPoolOptions;
|
|
|
|
const DEFAULT_MAX_CONNECTIONS: u32 = 10;
|
|
|
|
pub async fn create_pool(database_url: &str) -> Result<PgPool> {
|
|
let max_connections = std::env::var("DATABASE_MAX_CONNECTIONS")
|
|
.ok()
|
|
.and_then(|s| s.parse::<u32>().ok())
|
|
.unwrap_or(DEFAULT_MAX_CONNECTIONS);
|
|
|
|
let pool = PgPoolOptions::new()
|
|
.max_connections(max_connections)
|
|
.connect(database_url)
|
|
.await
|
|
.context("failed to connect to database")?;
|
|
|
|
sqlx::migrate!()
|
|
.run(&pool)
|
|
.await
|
|
.context("failed to run database migrations")?;
|
|
|
|
tracing::info!(max_connections, "database connected and migrations applied");
|
|
Ok(pool)
|
|
}
|