this repo has no description
0
fork

Configure Feed

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

feat: enhance database setup logging for SQLite and Postgres connections

+31 -7
+31 -7
server/src/database.rs
··· 8 8 9 9 pub(crate) async fn setup() -> Result<DbConn, LuminaError> { 10 10 let warn = "[WARN]".color_bright_orange().style_bold(); 11 + let info = "[INFO]".color_green().style_bold(); 11 12 match (std::env::var("LUMINA_DB_TYPE") 12 13 .map_err(|_| ConfMissing("LUMINA_DB_TYPE".to_string())) 13 14 .unwrap_or(String::from("sqlite"))) ··· 15 16 { 16 17 "sqlite" => { 17 18 let db_path = 18 - std::env::var("LUMINA_SQLITE_PATH").unwrap_or("instance.sqlite".to_string()); 19 + std::env::var("LUMINA_SQLITE_FILE").unwrap_or("instance.sqlite".to_string()); 20 + println!( 21 + "{info} Using SQLite database at path: {}", 22 + db_path.clone().color_bright_cyan().style_bold() 23 + ); 19 24 let manager = SqliteConnectionManager::file(db_path); 20 25 let pool = Pool::new(manager).map_err(LuminaError::SqlitePool)?; 21 26 { ··· 44 49 Ok(DbConn::SqliteConnectionPool(pool)) 45 50 } 46 51 "postgres" => { 52 + 47 53 let pg_config = { 54 + let mut uuu = ( 55 + "unspecified database".to_string(), 56 + "unspecified host".to_string(), 57 + "unkwown port".to_string(), 58 + ); 48 59 let mut pg_config = postgres::Config::new(); 49 60 pg_config.user(&{ 50 61 std::env::var("LUMINA_POSTGRES_USERNAME") 51 62 .map_err(|_| ConfMissing("LUMINA_POSTGRES_USERNAME".to_string()))? 52 63 }); 53 - pg_config.dbname(&{ 54 - std::env::var("LUMINA_POSTGRES_DATABASE") 55 - .map_err(|_| ConfMissing("LUMINA_POSTGRES_DATABASE".to_string()))? 56 - }); 57 - pg_config.port(std::env::var("LUMINA_POSTGRES_PORT").unwrap_or_else(|_| { 64 + let dbname = std::env::var("LUMINA_POSTGRES_DATABASE") 65 + .map_err(|_| ConfMissing("LUMINA_POSTGRES_DATABASE".to_string()))?; 66 + uuu.0 = dbname.clone(); 67 + pg_config.dbname(&dbname); 68 + let port = std::env::var("LUMINA_POSTGRES_PORT").unwrap_or_else(|_| { 58 69 eprintln!("{warn} No Postgres database port provided under environment variable 'LUMINA_POSTGRES_PORT'. Using default value '5432'."); 59 70 "5432".to_string() 60 - }).parse::<u16>().map_err(|_| { LuminaError::ConfInvalid("LUMINA_POSTGRES_PORT is not a valid integer number".to_string()) })?); 71 + }); 72 + uuu.2 = port.clone(); 73 + // Parse the port as u16, if it fails, return an error 74 + pg_config.port(port.parse::<u16>().map_err(|_| { LuminaError::ConfInvalid("LUMINA_POSTGRES_PORT is not a valid integer number".to_string()) })?); 61 75 match std::env::var("LUMINA_POSTGRES_HOST") { 62 76 Ok(val) => { 77 + uuu.1 = val.clone(); 63 78 pg_config.host(&val); 64 79 } 65 80 Err(_) => { 66 81 eprintln!( 67 82 "{warn} No Postgres database host provided under environment variable 'LUMINA_POSTGRES_HOST'. Using default value 'localhost'." 68 83 ); 84 + // Default to localhost if not set 85 + uuu.1 = "localhost".to_string(); 69 86 pg_config.host("localhost"); 70 87 } 71 88 }; ··· 79 96 ); 80 97 } 81 98 }; 99 + println!( 100 + "{info} Using Postgres database at: {} on host: {} at port: {}", 101 + uuu.0.color_bright_cyan().style_bold(), 102 + uuu.1.color_bright_cyan().style_bold(), 103 + uuu.2.color_bright_cyan().style_bold(), 104 + ); 82 105 pg_config 83 106 }; 107 + 84 108 // Connect to the database 85 109 let conn: (Client, Connection<Socket, NoTlsStream>) = pg_config 86 110 .connect(postgres::tls::NoTls)