feat:更新数据表结构
This commit is contained in:
@@ -5,46 +5,50 @@ from sqlalchemy.orm import relationship
|
||||
from models.base import AuditBase
|
||||
|
||||
|
||||
class Subject(AuditBase):
|
||||
name = Column(String(45), nullable=False)
|
||||
|
||||
modules = relationship("Module", back_populates="subject")
|
||||
library_files = relationship("LibraryFile", back_populates="subject")
|
||||
records = relationship("Record", back_populates="subject")
|
||||
mistakes = relationship("Mistake", back_populates="subject")
|
||||
|
||||
|
||||
class Module(AuditBase):
|
||||
subject_id = Column(BigInteger, ForeignKey("subject.id", ondelete="RESTRICT"), nullable=False, index=True)
|
||||
name = Column(String(45), nullable=False)
|
||||
|
||||
subject = relationship("Subject", back_populates="modules")
|
||||
library_files = relationship("LibraryFile", back_populates="module")
|
||||
|
||||
|
||||
class LibraryFile(AuditBase):
|
||||
subject = Column(String(45), nullable=False)
|
||||
module = Column(String(45), nullable=False)
|
||||
subject_id = Column(BigInteger, ForeignKey("subject.id", ondelete="RESTRICT"), nullable=False, index=True)
|
||||
module_id = Column(BigInteger, ForeignKey("module.id", ondelete="RESTRICT"), nullable=False, index=True)
|
||||
name = Column(String(45), nullable=False)
|
||||
type = Column(String(45), nullable=False)
|
||||
size = Column(Integer, nullable=False)
|
||||
content = Column(Text, nullable=False)
|
||||
|
||||
practice_record = relationship(
|
||||
"PracticeRecord",
|
||||
back_populates="library_file",
|
||||
cascade="all, delete-orphan"
|
||||
)
|
||||
subject = relationship("Subject", back_populates="library_files")
|
||||
module = relationship("Module", back_populates="library_files")
|
||||
|
||||
|
||||
class PracticeRecord(AuditBase):
|
||||
library_file_id = Column(BigInteger, ForeignKey("library_file.id"), nullable=False)
|
||||
|
||||
class Record(AuditBase):
|
||||
type = Column(String(45), nullable=False)
|
||||
subject_id = Column(BigInteger, ForeignKey("subject.id", ondelete="RESTRICT"), nullable=False, index=True)
|
||||
total_count = Column(Integer, nullable=False)
|
||||
correct_count = Column(Integer, nullable=False)
|
||||
wrong_count = Column(Integer, nullable=False)
|
||||
|
||||
library_file = relationship(
|
||||
"LibraryFile",
|
||||
back_populates="practice_record",
|
||||
)
|
||||
|
||||
|
||||
class ExamRecord(AuditBase):
|
||||
subject = Column(String(45), nullable=False)
|
||||
total_count = Column(Integer, nullable=False)
|
||||
correct_count = Column(Integer, nullable=False)
|
||||
wrong_count = Column(Integer, nullable=False)
|
||||
subject = relationship("Subject", back_populates="records")
|
||||
|
||||
|
||||
class Mistake(AuditBase):
|
||||
subject = Column(String(45), nullable=False)
|
||||
module = Column(String(45), nullable=False)
|
||||
name = Column(String(45), nullable=False)
|
||||
subject_id = Column(BigInteger, ForeignKey("subject.id", ondelete="RESTRICT"), nullable=False, index=True)
|
||||
type = Column(String(45), nullable=False)
|
||||
question = Column(Text, nullable=False)
|
||||
options = Column(JSONB, nullable=False)
|
||||
answer = Column(JSONB, nullable=False)
|
||||
|
||||
subject = relationship("Subject", back_populates="mistakes")
|
||||
|
||||
Reference in New Issue
Block a user