Files
meijiaka-zy/python-api/app/models/update.py
T
小鱼开发 cbd4068776 fix(db): unify table name prefix to mjk_ for update tables
- Rename app_releases → mjk_app_releases
- Rename release_packages → mjk_release_packages
- Update ForeignKey reference and migration file
- Add pre-commit hook: check_table_prefix.py to prevent future violations
2026-05-15 18:28:07 +08:00

65 lines
2.3 KiB
Python

"""
应用更新模型
============
Tauri updater 插件所需的数据结构。
"""
from datetime import UTC, datetime
from sqlalchemy import Boolean, BigInteger, DateTime, ForeignKey, Integer, String, Text, UniqueConstraint
from sqlalchemy.orm import Mapped, mapped_column, relationship
from app.db.session import Base
class AppRelease(Base):
"""应用版本发布记录"""
__tablename__ = "mjk_app_releases"
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
version: Mapped[str] = mapped_column(String(20), unique=True, nullable=False, index=True)
release_date: Mapped[datetime] = mapped_column(DateTime(timezone=True), nullable=False)
notes: Mapped[str] = mapped_column(Text, nullable=False, default="")
mandatory: Mapped[bool] = mapped_column(Boolean, default=False)
created_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), default=lambda: datetime.now(UTC), nullable=False
)
packages: Mapped[list["ReleasePackage"]] = relationship(
"ReleasePackage",
back_populates="release",
cascade="all, delete-orphan",
lazy="selectin",
)
class ReleasePackage(Base):
"""平台安装包信息"""
__tablename__ = "mjk_release_packages"
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
release_id: Mapped[int] = mapped_column(
Integer,
ForeignKey("mjk_app_releases.id", ondelete="CASCADE"),
nullable=False,
)
platform: Mapped[str] = mapped_column(String(20), nullable=False)
architecture: Mapped[str] = mapped_column(String(20), nullable=False)
filename: Mapped[str] = mapped_column(String(255), nullable=False)
file_url: Mapped[str] = mapped_column(String(500), nullable=False)
file_size: Mapped[int] = mapped_column(BigInteger, nullable=False)
signature: Mapped[str] = mapped_column(Text, nullable=False)
download_count: Mapped[int] = mapped_column(Integer, default=0)
created_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), default=lambda: datetime.now(UTC), nullable=False
)
release: Mapped["AppRelease"] = relationship("AppRelease", back_populates="packages")
__table_args__ = (
UniqueConstraint("release_id", "platform", "architecture", name="uix_pkg_platform_arch"),
)