40 lines
1.3 KiB
Python
40 lines
1.3 KiB
Python
import uuid
|
|
from datetime import datetime
|
|
|
|
from sqlalchemy import String, DateTime, ForeignKey, Index, func, Text
|
|
from sqlalchemy import Uuid
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from app.database import Base
|
|
|
|
|
|
class QueryTask(Base):
|
|
__tablename__ = "query_tasks"
|
|
|
|
id: Mapped[uuid.UUID] = mapped_column(
|
|
Uuid(as_uuid=True),
|
|
primary_key=True,
|
|
default=uuid.uuid4,
|
|
)
|
|
query_id: Mapped[uuid.UUID] = mapped_column(
|
|
Uuid(as_uuid=True),
|
|
ForeignKey("queries.id", ondelete="CASCADE"),
|
|
nullable=False,
|
|
)
|
|
platform: Mapped[str] = mapped_column(String(50), nullable=False)
|
|
status: Mapped[str] = mapped_column(String(20), default="pending")
|
|
error_message: Mapped[str | None] = mapped_column(Text, nullable=True)
|
|
scheduled_at: Mapped[datetime] = mapped_column(
|
|
DateTime(timezone=True),
|
|
server_default=func.now(),
|
|
nullable=False,
|
|
)
|
|
started_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True)
|
|
completed_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True)
|
|
|
|
query: Mapped["Query"] = relationship("Query", back_populates="query_tasks")
|
|
|
|
__table_args__ = (
|
|
Index("idx_query_tasks_status", "status"),
|
|
)
|