-
Notifications
You must be signed in to change notification settings - Fork 1
feat(db): read SQLAlchemy engine configuration from config file #73
Copy link
Copy link
Closed
Description
Problem
SQLAlchemy engine pool parameters are currently hardcoded in src/infrastructure/db/factory.py:
def create_engine(
db_config: PostgresConfig,
pool_size: int = 30,
pool_timeout: int = 30,
pool_recycle: int = 3600,
max_overflow: int = 20,
) -> AsyncEngine:These values cannot be changed without modifying the source code, which makes it impossible to tune the connection pool per environment (dev, staging, production).
Current State
PostgresConfig in src/infrastructure/config.py only exposes:
- Connection parameters (
host,port,user,password,db) echoflag
Hardcoded in create_engine:
| Parameter | Hardcoded Value |
|---|---|
pool_size |
30 |
pool_timeout |
30 |
pool_recycle |
3600 |
max_overflow |
20 |
Not configurable at all:
pool_pre_ping(recommended for detecting stale connections)echo_pool(useful for debugging connection pool behavior)
Proposed Solution
- Add engine pool fields to
PostgresConfiginsrc/infrastructure/config.pywith sensible defaults:
class PostgresConfig(BaseModel):
host: str
port: int
user: str
password: str
db: str
echo: bool = False
# Engine pool configuration
pool_size: int = 30
pool_timeout: int = 30
pool_recycle: int = 3600
max_overflow: int = 20
pool_pre_ping: bool = True
echo_pool: bool = False-
Update
create_engineinsrc/infrastructure/db/factory.pyto read from config instead of function defaults. -
Update
config-example.yamlwith the new postgres fields (commented out with default values).
Benefits
- Environment-specific pool tuning without code changes
- Production can use larger pools, dev/test can use smaller ones
pool_pre_pingenabled by default improves connection reliability- Consistent with how other settings (log level, auth, etc.) are already managed
Files to Change
src/infrastructure/config.pysrc/infrastructure/db/factory.pyconfig-example.yaml
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels