from datetime import datetime from decimal import Decimal from sqlalchemy import BigInteger, DateTime, ForeignKey, Numeric, String, func from sqlalchemy.orm import Mapped, mapped_column from app.db.base import Base class PriceRuleRecord(Base): __tablename__ = "price_rules" id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=True) price_rule_id: Mapped[str] = mapped_column(String(32), unique=True, index=True, nullable=False) scheme_id: Mapped[str] = mapped_column( String(32), ForeignKey("schemes.scheme_id", ondelete="RESTRICT"), nullable=False, index=True, ) pricing_category_id: Mapped[str | None] = mapped_column( String(32), ForeignKey("pricing_categories.pricing_category_id", ondelete="SET NULL"), nullable=True, index=True, ) target_type: Mapped[str] = mapped_column(String(32), nullable=False) target_ref: Mapped[str] = mapped_column(String(255), nullable=False) amount: Mapped[Decimal] = mapped_column(Numeric(12, 2), nullable=False) currency: Mapped[str] = mapped_column(String(3), nullable=False, default="RUB") created_at: Mapped[datetime] = mapped_column( DateTime(timezone=True), nullable=False, server_default=func.now(), )