"""Market price cache model for storing Yahoo Finance data.""" from sqlalchemy import Column, Integer, String, Numeric, DateTime, Index from datetime import datetime from app.database import Base class MarketPrice(Base): """ Cache table for market prices from Yahoo Finance. Stores the last fetched price for each symbol to reduce API calls. """ __tablename__ = "market_prices" id = Column(Integer, primary_key=True, index=True) symbol = Column(String(20), unique=True, nullable=False, index=True) price = Column(Numeric(precision=20, scale=6), nullable=False) fetched_at = Column(DateTime, nullable=False, default=datetime.utcnow) source = Column(String(50), default="yahoo_finance") # Index for quick lookups by symbol and freshness checks __table_args__ = ( Index('idx_symbol_fetched', 'symbol', 'fetched_at'), ) def __repr__(self): return f""