from datetime import datetime from sqlalchemy import DateTime, Integer, String, Text from sqlalchemy.orm import Mapped, mapped_column from app.core.database import Base from app.core.utils.time import utc_now from app.modules.business.constants import ( StatusValue, ) from app.modules.business.models.common import TimestampMixin class LegacySyncRun(Base, TimestampMixin): __tablename__ = "legacy_sync_runs" id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True) code: Mapped[str] = mapped_column(String(64), unique=True, index=True) domain: Mapped[str] = mapped_column(String(128), index=True) source_table: Mapped[str | None] = mapped_column(String(128), nullable=True, index=True) status: Mapped[str] = mapped_column(String(32), default=StatusValue.RUNNING, index=True) started_at: Mapped[datetime] = mapped_column(DateTime, default=utc_now, index=True) finished_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True) created_count: Mapped[int] = mapped_column(Integer, default=0) updated_count: Mapped[int] = mapped_column(Integer, default=0) skipped_count: Mapped[int] = mapped_column(Integer, default=0) error_message: Mapped[str | None] = mapped_column(Text, nullable=True) note: Mapped[str | None] = mapped_column(Text, nullable=True)