Your music, beautifully tracked. All yours. (coming soon) teal.fm
teal-fm atproto
at fix-compose-path 40 lines 1.3 kB view raw
1use sqlx::postgres::{PgPool, PgPoolOptions}; 2use std::env; 3use tracing::info; 4 5fn censor_url(url: &str) -> String { 6 let password_start = url.find(':').unwrap_or(0) + 1; 7 let password_end = url.find('@').unwrap_or(url.len()); 8 9 if password_start > 0 && password_start < password_end && password_end <= url.len() { 10 let mut censored_url = String::with_capacity(url.len()); 11 censored_url.push_str(&url[..password_start]); 12 censored_url.push_str("*****"); 13 censored_url.push_str(&url[password_end..]); 14 censored_url 15 } else { 16 url.to_string() 17 } 18} 19 20pub async fn init_pool() -> anyhow::Result<PgPool, anyhow::Error> { 21 info!( 22 target: "db", 23 "Connecting to the database at url {}", 24 censor_url(&env::var("DATABASE_URL")?) 25 ); 26 let pool = PgPoolOptions::new() 27 .max_connections(50) 28 .min_connections(1) 29 .max_lifetime(std::time::Duration::from_secs(10)) 30 .connect(&env::var("DATABASE_URL")?) 31 .await?; 32 info!(target: "db", "Connected to the database!"); 33 34 // run migrations 35 info!(target: "db", "Running migrations..."); 36 //sqlx::migrate!().run(&pool).await?; 37 38 info!(target: "db", "Migrations complete!"); 39 Ok(pool) 40}