From 86e815b4e248d6c82b48d7692c89ebd6d40ec240 Mon Sep 17 00:00:00 2001 From: jimmy-sketch Date: Fri, 25 Jul 2025 12:34:56 +0800 Subject: [PATCH] =?UTF-8?q?feat(database):=20=E6=96=B0=E5=A2=9E=20Score=20?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E6=A8=A1=E5=9E=8B=E5=B9=B6=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=20User=20=E5=85=B3=E7=B3=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 创建 Score 类作为成绩数据库模型,对应 osu! API 中的 Score 对象 - 在 User 模型中添加与 Score 的关系- 优化了数据库表结构,增加了索引和字段约束 --- app/database/score.py | 41 +++++++++++++++++++++++++++++++++++++++++ app/database/user.py | 3 ++- 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 app/database/score.py diff --git a/app/database/score.py b/app/database/score.py new file mode 100644 index 0000000..3919ce5 --- /dev/null +++ b/app/database/score.py @@ -0,0 +1,41 @@ +from __future__ import annotations + +from datetime import datetime +from . import User +from sqlalchemy import Column, DateTime +from sqlmodel import Field, Relationship, SQLModel + +class Score(SQLModel, table=True): + """ + 成绩数据库模型,对应osu! API中的Score对象 + 参考: https://osu.ppy.sh/docs/index.html#score + 数据库表结构参考: migrations/base.sql + """ + __tablename__ = "scores" + + # 基本字段 + id: int = Field(primary_key=True) + map_md5: str = Field(max_length=32, index=True) + score: int + pp: float + acc: float + max_combo: int + mods: int = Field(index=True) + n300: int + n100: int + n50: int + nmiss: int + ngeki: int + nkatu: int + grade: str = Field(default="N", max_length=2) + status: int = Field(index=True) + mode: int = Field(index=True) + play_time: datetime = Field(sa_column=Column(DateTime, index=True)) + time_elapsed: int + client_flags: int + userid: int = Field(index=True) + perfect: bool + online_checksum: str = Field(max_length=32, index=True) + + # 关联关系 + user: "User" = Relationship(back_populates="scores") diff --git a/app/database/user.py b/app/database/user.py index a25e3e1..6534758 100644 --- a/app/database/user.py +++ b/app/database/user.py @@ -1,4 +1,6 @@ # ruff: noqa: I002 +from __future__ import annotations + from dataclasses import dataclass from datetime import datetime from typing import Optional @@ -95,7 +97,6 @@ class User(SQLModel, table=True): back_populates="user" ) - # ============================================ # Lazer API 专用表模型 # ============================================