from datetime import date, datetime, timezone from sqlalchemy import Date, DateTime, Float, ForeignKey, Index, Integer, String, Text from sqlalchemy.orm import Mapped, mapped_column from app.database import Base class UpstreamRechargeEvent(Base): __tablename__ = "upstream_recharge_events" id: Mapped[int] = mapped_column(Integer, primary_key=True, index=True) upstream_id: Mapped[int] = mapped_column(Integer, ForeignKey("upstreams.id", ondelete="CASCADE"), index=True) recharge_date: Mapped[date] = mapped_column(Date, nullable=False) amount: Mapped[float] = mapped_column(Float, nullable=False) note: Mapped[str] = mapped_column(Text, default="") created_at: Mapped[datetime] = mapped_column(DateTime, default=lambda: datetime.now(timezone.utc)) updated_at: Mapped[datetime] = mapped_column( DateTime, default=lambda: datetime.now(timezone.utc), onupdate=lambda: datetime.now(timezone.utc) ) __table_args__ = ( Index("ix_recharge_upstream_date", "upstream_id", "recharge_date"), )