An easy-to-host PDS on the ATProtocol, iPhone and MacOS. Maintain control of your keys and data, always.
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat(relay): wire db pool and migrations into startup sequence

authored by

Malpercio and committed by
Tangled
1c4c52ef 5798ac51

+26 -1
+26 -1
crates/relay/src/main.rs
··· 3 3 use std::{path::PathBuf, sync::Arc}; 4 4 5 5 mod app; 6 - #[allow(dead_code)] 7 6 mod db; 8 7 9 8 #[derive(Parser)] ··· 42 41 ); 43 42 44 43 let addr = format!("{}:{}", config.bind_address, config.port); 44 + 45 + // **Intentional deviation from design:** The design doc's startup sequence shows 46 + // `open_pool(&config.database_url)` directly. However, `config.database_url` defaults 47 + // to a plain filesystem path (e.g. `/var/pds/relay.db`) when not explicitly set, which 48 + // is not a valid sqlx URL. We format it here rather than changing Config or open_pool, 49 + // keeping both functions general-purpose. 50 + // 51 + // Plain absolute paths like "/var/pds/relay.db" become "sqlite:///var/pds/relay.db". 52 + // Already-formatted "sqlite://..." URLs pass through unchanged. 53 + let db_url = if config.database_url.starts_with("sqlite:") { 54 + config.database_url.clone() 55 + } else if config.database_url.starts_with('/') { 56 + format!("sqlite://{}", config.database_url) 57 + } else { 58 + format!("sqlite:{}", config.database_url) 59 + }; 60 + 61 + let pool = db::open_pool(&db_url) 62 + .await 63 + .with_context(|| format!("failed to open database at {}", config.database_url))?; 64 + 65 + db::run_migrations(&pool) 66 + .await 67 + .with_context(|| "failed to run database migrations")?; 68 + 45 69 let state = app::AppState { 46 70 config: Arc::new(config), 71 + db: pool, 47 72 }; 48 73 49 74 let listener = tokio::net::TcpListener::bind(&addr)