26 lines
1.0 KiB
Python
26 lines
1.0 KiB
Python
"""每日心情叶模型"""
|
|
|
|
from datetime import datetime, date
|
|
|
|
from sqlalchemy import String, Text, DateTime, Date, ForeignKey, UniqueConstraint
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from app.database import Base
|
|
|
|
|
|
class DailyMoodLeaf(Base):
|
|
__tablename__ = "daily_mood_leaves"
|
|
__table_args__ = (
|
|
UniqueConstraint("user_id", "leaf_date", name="uq_user_daily_leaf"),
|
|
)
|
|
|
|
id: Mapped[str] = mapped_column(String(36), primary_key=True)
|
|
user_id: Mapped[str] = mapped_column(String(36), ForeignKey("users.id", ondelete="CASCADE"))
|
|
leaf_date: Mapped[date] = mapped_column(Date, nullable=False)
|
|
mood: Mapped[str | None] = mapped_column(String(20), nullable=True) # 预设心情标签
|
|
note: Mapped[str | None] = mapped_column(Text, nullable=True) # 心情备注
|
|
leaf_seed: Mapped[str] = mapped_column(String(32), nullable=False) # 确定性生成种子
|
|
created_at: Mapped[datetime] = mapped_column(DateTime, default=lambda: datetime.utcnow())
|
|
|
|
user = relationship("User", foreign_keys=[user_id])
|