@@ -5,11 +5,42 @@ use std::net::SocketAddr;
55
66use  serde:: { Deserialize ,  Serialize } ; 
77use  thegraph_core:: { Address ,  DeploymentId } ; 
8+ use  tracing:: warn; 
89
910#[ derive( Clone ,  Debug ,  Deserialize ,  Serialize ) ]  
1011pub  struct  DatabaseConfig  { 
1112    pub  postgres_url :  String , 
1213} 
14+ impl  DatabaseConfig  { 
15+     pub  fn  format_db_config ( 
16+         ps_url :  Option < String > , 
17+         ps_host :  Option < String > , 
18+         ps_pwd :  Option < String > , 
19+         ps_port :  Option < String > , 
20+         ps_user :  Option < String > , 
21+         ps_db :  Option < String > , 
22+     )  -> Self  { 
23+         let  db_config = ( ps_url,  ps_host,  ps_pwd,  ps_port,  ps_user,  ps_db) ; 
24+         match  db_config { 
25+             ( Some ( url) ,  ..)  if  !url. is_empty ( )  => DatabaseConfig  {  postgres_url :  url } , 
26+             ( None ,  Some ( host) ,  Some ( pwd) ,  Some ( port) ,  Some ( user) ,  Some ( dbname) )  => { 
27+                 let  postgres_url =
28+                     format ! ( "postgres://{}:{}@{}:{}/{}" ,  user,  pwd,  host,  port,  dbname) ; 
29+                 DatabaseConfig  {  postgres_url } 
30+             } 
31+             _ => { 
32+                 warn ! ( 
33+                     "Some configuration values are missing for database values, please make sure you either \  
34+ 
35+                 " ) ; 
36+                 // This will eventually fail to connect 
37+                 DatabaseConfig  { 
38+                     postgres_url :  String :: new ( ) , 
39+                 } 
40+             } 
41+         } 
42+     } 
43+ } 
1344
1445#[ derive( Clone ,  Debug ,  Deserialize ,  Serialize ) ]  
1546pub  struct  SubgraphConfig  { 
0 commit comments