nex_buddy/server/app/models/fortune.py

40 lines
1.7 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

"""月度运势:星座 × 月份的管理端文案。
两层数据:
* ``scope='month'`` 通用月度模板 —— period 存 ``'01'``..``'12'``,每年都适用;
* ``scope='ym'`` 指定年月 —— period 存 ``'2026-11'``,优先级高于模板。
设备端取运势的顺序:指定年月 → 通用月度 → 没有(前端自行兜底文案)。
中英文各存一份(``content`` / ``content_en``),平台中英文切换直接取对应列。
"""
from __future__ import annotations
from datetime import datetime
from sqlalchemy import Boolean, DateTime, Integer, String, Text, UniqueConstraint, func
from sqlalchemy.orm import Mapped, mapped_column
from app.db.session import Base
class Fortune(Base):
__tablename__ = "zodiac_fortunes"
__table_args__ = (UniqueConstraint("zodiac_code", "scope", "period", name="uq_fortune_period"),)
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
zodiac_code: Mapped[str] = mapped_column(String(16), index=True) # aries / ...
scope: Mapped[str] = mapped_column(String(8)) # month / ym
period: Mapped[str] = mapped_column(String(7)) # '11' 或 '2026-11'
title: Mapped[str] = mapped_column(String(64), default="")
title_en: Mapped[str] = mapped_column(String(128), default="")
content: Mapped[str] = mapped_column(Text, default="") # 中文
content_en: Mapped[str] = mapped_column(Text, default="") # English,空则回退中文
enabled: Mapped[bool] = mapped_column(Boolean, default=True)
updated_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), server_default=func.now(), onupdate=func.now()
)