- Remove hardcoded database_url/jwt_secret defaults, require env vars - Add DB indexes for stocks.market, market_cap, backtests.user_id - Optimize backtest engine: preload all prices, move stock_names out of loop - Fix backtest API auth: filter by user_id at query level (6 endpoints) - Add manual transaction entry modal on portfolio detail page - Replace console.error with toast.error in signals, backtest, data explorer - Add backtest delete button with confirmation dialog - Replace simulated sine chart with real snapshot data - Add strategy-to-portfolio apply flow with dialog - Add DC pension risk asset ratio >70% warning on rebalance page - Add backtest comparison page with metrics table and overlay chart
29 lines
684 B
Python
29 lines
684 B
Python
"""
|
|
Database connection and session management.
|
|
"""
|
|
|
|
from sqlalchemy import create_engine
|
|
from sqlalchemy.orm import sessionmaker, declarative_base
|
|
from app.core.config import get_settings
|
|
|
|
settings = get_settings()
|
|
|
|
_engine_kwargs = {"pool_pre_ping": True}
|
|
if settings.database_url.startswith("postgresql"):
|
|
_engine_kwargs.update(pool_size=10, max_overflow=20)
|
|
|
|
engine = create_engine(settings.database_url, **_engine_kwargs)
|
|
|
|
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
|
|
|
Base = declarative_base()
|
|
|
|
|
|
def get_db():
|
|
"""Dependency for getting database session."""
|
|
db = SessionLocal()
|
|
try:
|
|
yield db
|
|
finally:
|
|
db.close()
|