from sqlalchemy import Boolean, Column, Integer, String, DateTime, CheckConstraint from sqlalchemy.sql import func from app.db.base import Base import enum class PriorityEnum(str, enum.Enum): LOW = "low" MEDIUM = "medium" HIGH = "high" class Todo(Base): __tablename__ = "todos" id = Column(Integer, primary_key=True, index=True) title = Column(String, index=True) description = Column(String, nullable=True) completed = Column(Boolean, default=False) priority = Column(String(10), default=PriorityEnum.MEDIUM.value) due_date = Column(DateTime(timezone=True), nullable=True) created_at = Column(DateTime(timezone=True), server_default=func.now()) updated_at = Column(DateTime(timezone=True), onupdate=func.now()) # Add a check constraint to ensure priority is one of the allowed values __table_args__ = ( CheckConstraint( "priority IN ('low', 'medium', 'high')", name="priority_check" ), )