3636@dataclass
3737class DatabaseConfig :
3838 """Database configuration for warehouse operations."""
39- host : str = os . getenv ( "PGHOST" , " localhost")
40- port : int = int ( os . getenv ( "PGPORT" , " 5435" ))
41- database : str = os . getenv ( "POSTGRES_DB" , " warehouse")
42- user : str = os . getenv ( "POSTGRES_USER" , " warehouse")
43- password : str = os . getenv ( "POSTGRES_PASSWORD" , "" )
39+ host : str = " localhost"
40+ port : int = 5435
41+ database : str = " warehouse"
42+ user : str = " warehouse"
43+ password : str = ""
4444 min_size : int = 1
4545 max_size : int = 10
46+
47+ @classmethod
48+ def from_env (cls ) -> "DatabaseConfig" :
49+ """Create DatabaseConfig from environment variables (lazy initialization)."""
50+ return cls (
51+ host = os .getenv ("PGHOST" , "localhost" ),
52+ port = int (os .getenv ("PGPORT" , "5435" )),
53+ database = os .getenv ("POSTGRES_DB" , "warehouse" ),
54+ user = os .getenv ("POSTGRES_USER" , "warehouse" ),
55+ password = os .getenv ("POSTGRES_PASSWORD" , "" ),
56+ min_size = 1 ,
57+ max_size = 10 ,
58+ )
4659
4760class SQLRetriever :
4861 """
@@ -62,7 +75,8 @@ def __new__(cls, config: Optional[DatabaseConfig] = None):
6275
6376 def __init__ (self , config : Optional [DatabaseConfig ] = None ):
6477 if not self ._initialized :
65- self .config = config or DatabaseConfig ()
78+ # Lazy initialization: only read env vars when actually creating config
79+ self .config = config or DatabaseConfig .from_env ()
6680 self ._pool : Optional [asyncpg .Pool ] = None
6781 self ._initialized = True
6882
0 commit comments