31 lines
1.0 KiB
Python
31 lines
1.0 KiB
Python
"""Finance daily summary snapshot model.
|
|
|
|
Stores pre-computed daily reconciliation results in a single JSON column.
|
|
This keeps the schema stable: adding new summary fields requires no migration.
|
|
"""
|
|
from datetime import date, datetime, timezone
|
|
from typing import Optional
|
|
|
|
from sqlalchemy import Boolean, Date, DateTime, Integer, Text, UniqueConstraint
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from app.database import Base
|
|
|
|
|
|
def _utcnow() -> datetime:
|
|
return datetime.now(timezone.utc)
|
|
|
|
|
|
class FinanceDailySummary(Base):
|
|
__tablename__ = "finance_daily_summaries"
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, index=True)
|
|
stat_date: Mapped[date] = mapped_column(Date, unique=True, nullable=False, index=True)
|
|
summary_json: Mapped[str] = mapped_column(Text, nullable=False)
|
|
success: Mapped[bool] = mapped_column(Boolean, default=False, index=True)
|
|
computed_at: Mapped[datetime] = mapped_column(DateTime, default=_utcnow)
|
|
|
|
__table_args__ = (
|
|
UniqueConstraint("stat_date", name="uq_finance_summary_date"),
|
|
)
|