Files
DoubaoTeam/models/score.py
T
2026-09-21 19:55:51 +08:00

55 lines
2.1 KiB
Python

from sqlalchemy import *
from sqlalchemy.dialects.mysql import TINYINT
from core.database import Base
from datetime import datetime,date
class Score(Base):
__tablename__ = "scores"
id = Column(Integer
, primary_key=True
,autoincrement=True
,comment="成绩表序号,自增主键"
)
student_id = Column(Integer
,ForeignKey("students.id")
,nullable=False
,comment="学生学号"
)
score = Column(DECIMAL(4,1)
,CheckConstraint("score between 0 and 100")
,nullable=False
)
exam_seq= Column(Integer
, nullable=False
,comment="考试序次")
__table_args__ = (
UniqueConstraint("student_id"
, "exam_seq"
, name="uk_scores_student_exam"),
)#学生id和考核序次联合唯一,即一个学生一次考试只能有一个分数
exam_date=Column(Date
,default=date.today
,comment="考试日期"
)
created_at=Column(DateTime
,default=datetime.now
,server_default=text("CURRENT_TIMESTAMP")
,nullable=False
,comment="创建时间"
)
updated_at=Column(DateTime
,default=datetime.now
,onupdate=datetime.now
,server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP")
,nullable=False
,comment="更新时间"
)
remark=Column(String(255)
,comment="备注说明"
)
is_deleted=Column(TINYINT
,default=0
,server_default=text("0")
,nullable=False
,comment="逻辑删除标记:未删除0,已删除1"
)