from __future__ import annotations from datetime import datetime, timezone from sqlalchemy import DateTime, ForeignKey, Integer, Numeric, String, Text, func from sqlalchemy.orm import Mapped, mapped_column from app.db.base import Base def _utcnow() -> datetime: return datetime.now(timezone.utc) class OrderRecord(Base): __tablename__ = "order_record" id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True) user_id: Mapped[int] = mapped_column(Integer, ForeignKey("user.id"), nullable=False, index=True) platform: Mapped[str] = mapped_column(String(30), nullable=False) store_name: Mapped[str] = mapped_column(String(128), nullable=False) dishes: Mapped[str] = mapped_column(Text, nullable=False, default="[]") order_date: Mapped[str] = mapped_column(String(10), nullable=False) price: Mapped[str] = mapped_column(String(20), nullable=False) original_price: Mapped[str | None] = mapped_column(String(20), nullable=True) savings: Mapped[str | None] = mapped_column(String(20), nullable=True) created_at: Mapped[datetime] = mapped_column( DateTime(timezone=True), server_default=func.now(), nullable=False )