25 lines
753 B
Python
25 lines
753 B
Python
"""Task ORM model."""
|
|
|
|
import uuid
|
|
|
|
from sqlalchemy import Boolean, Column, DateTime, ForeignKey, String
|
|
from sqlalchemy.orm import relationship
|
|
from sqlalchemy.sql import func
|
|
|
|
from .base import Base
|
|
|
|
|
|
class Task(Base):
|
|
__tablename__ = "tasks"
|
|
|
|
id = Column(String(36), primary_key=True, default=lambda: str(uuid.uuid4()))
|
|
account_id = Column(String(36), ForeignKey("accounts.id", ondelete="CASCADE"), nullable=False)
|
|
cron_expression = Column(String(50), nullable=False)
|
|
is_enabled = Column(Boolean, default=True)
|
|
created_at = Column(DateTime, server_default=func.now())
|
|
|
|
account = relationship("Account", back_populates="tasks")
|
|
|
|
def __repr__(self):
|
|
return f"<Task(id={self.id}, cron='{self.cron_expression}')>"
|