SQLAlchemy 2.0 defaults to mapping Python enum *names* (OPEN, CLOSED) to DB values, but MySQL stores lowercase *values* (open, closed). This mismatch causes LookupError on read. Adding values_callable=lambda x: [e.value for e in x] tells SQLAlchemy to use the enum values for DB mapping. Affected models: milestone, task, meeting, propose, support
36 lines
1.4 KiB
Python
36 lines
1.4 KiB
Python
from sqlalchemy import Column, Integer, String, Text, DateTime, ForeignKey, Enum
|
|
from sqlalchemy.orm import relationship
|
|
from sqlalchemy.sql import func
|
|
from app.core.config import Base
|
|
import enum
|
|
|
|
class SupportStatus(str, enum.Enum):
|
|
OPEN = "open"
|
|
IN_PROGRESS = "in_progress"
|
|
RESOLVED = "resolved"
|
|
CLOSED = "closed"
|
|
|
|
class SupportPriority(str, enum.Enum):
|
|
LOW = "low"
|
|
MEDIUM = "medium"
|
|
HIGH = "high"
|
|
CRITICAL = "critical"
|
|
|
|
class Support(Base):
|
|
__tablename__ = "supports"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
title = Column(String(255), nullable=False)
|
|
description = Column(Text, nullable=True)
|
|
status = Column(Enum(SupportStatus, values_callable=lambda x: [e.value for e in x]), default=SupportStatus.OPEN)
|
|
priority = Column(Enum(SupportPriority, values_callable=lambda x: [e.value for e in x]), default=SupportPriority.MEDIUM)
|
|
support_code = Column(String(64), nullable=True, unique=True, index=True)
|
|
|
|
project_id = Column(Integer, ForeignKey("projects.id"), nullable=False)
|
|
milestone_id = Column(Integer, ForeignKey("milestones.id"), nullable=False)
|
|
reporter_id = Column(Integer, ForeignKey("users.id"), nullable=False)
|
|
assignee_id = Column(Integer, ForeignKey("users.id"), nullable=True)
|
|
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
updated_at = Column(DateTime(timezone=True), onupdate=func.now())
|