67 lines
2.2 KiB
Python
67 lines
2.2 KiB
Python
from sqlalchemy import (Boolean, Column, DateTime, Float, ForeignKey, Integer,
|
|
String)
|
|
from sqlalchemy.orm import relationship
|
|
|
|
from src.database import Base
|
|
|
|
|
|
class User(Base):
|
|
"""The database model for users"""
|
|
|
|
__tablename__ = "users"
|
|
|
|
user_id = Column(Integer, primary_key=True, index=True)
|
|
username = Column(String, unique=True, index=True, nullable=False)
|
|
hashed_password = Column(String, nullable=False)
|
|
avatar_index = Column(Integer, nullable=False)
|
|
playtime = Column(Float, nullable=False)
|
|
|
|
high_scores = relationship(
|
|
"HighScore", back_populates="owner", cascade="all, delete", lazy="dynamic"
|
|
)
|
|
course_progress = relationship(
|
|
"CourseProgress", back_populates="owner", cascade="all, delete", lazy="dynamic"
|
|
)
|
|
|
|
|
|
class HighScore(Base):
|
|
"""The database model for high scores"""
|
|
|
|
__tablename__ = "high_scores"
|
|
|
|
high_score_id = Column(Integer, primary_key=True, index=True)
|
|
score_value = Column(Float, nullable=False)
|
|
time = Column(DateTime, nullable=False)
|
|
minigame = Column(String, nullable=False)
|
|
owner_id = Column(Integer, ForeignKey("users.user_id"))
|
|
owner = relationship("User", back_populates="high_scores")
|
|
|
|
|
|
class CourseProgress(Base):
|
|
"""The database model for course progress"""
|
|
|
|
__tablename__ = "course_progress"
|
|
|
|
course_progress_id = Column(Integer, primary_key=True, index=True)
|
|
progress = Column(Float, nullable=False)
|
|
course = Column(String, nullable=False)
|
|
owner_id = Column(Integer, ForeignKey("users.user_id"))
|
|
owner = relationship("User", back_populates="course_progress")
|
|
learnables = relationship("LearnableProgress", back_populates="course")
|
|
|
|
|
|
class LearnableProgress(Base):
|
|
"""The database model for learnable progress"""
|
|
|
|
__tablename__ = "learnable_progress"
|
|
|
|
learnable_progress_id = Column(Integer, primary_key=True, index=True)
|
|
index = Column(Integer, nullable=False)
|
|
in_use = Column(Boolean, nullable=False)
|
|
name = Column(String, unique=True, nullable=False)
|
|
progress = Column(Float, nullable=False)
|
|
course_progress_id = Column(
|
|
Integer, ForeignKey("course_progress.course_progress_id")
|
|
)
|
|
course = relationship("CourseProgress", back_populates="learnables")
|