Start working on database models
This commit is contained in:
12
src/database.py
Normal file
12
src/database.py
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
from sqlalchemy import create_engine
|
||||||
|
from sqlalchemy.ext.declarative import declarative_base
|
||||||
|
from sqlalchemy.orm import sessionmaker
|
||||||
|
|
||||||
|
# SQLALCHEMY_DATABASE_URL = "sqlite:///./sql_app.db"
|
||||||
|
SQLALCHEMY_DATABASE_URL = "postgresql://user:password@postgresserver/db"
|
||||||
|
|
||||||
|
engine = create_engine(SQLALCHEMY_DATABASE_URL)
|
||||||
|
|
||||||
|
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
||||||
|
|
||||||
|
Base = declarative_base()
|
||||||
11
src/enums.py
Normal file
11
src/enums.py
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
from enum import Enum
|
||||||
|
|
||||||
|
class MinigameEnum(str, Enum):
|
||||||
|
SpellingBee = 'SpellingBee'
|
||||||
|
Hangman = 'Hangman'
|
||||||
|
JustSign = 'JustSign'
|
||||||
|
|
||||||
|
|
||||||
|
class CourseEnum(str, Enum):
|
||||||
|
Fingerspelling = 'Fingerspelling'
|
||||||
|
Animals = 'Animals'
|
||||||
34
src/models.py
Normal file
34
src/models.py
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
from sqlalchemy import Boolean, Column, ForeignKey, Integer, String
|
||||||
|
from sqlalchemy.orm import relationship
|
||||||
|
|
||||||
|
from .enums import MinigameEnum, CourseEnum
|
||||||
|
from .database import Base
|
||||||
|
|
||||||
|
|
||||||
|
class User(Base):
|
||||||
|
__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)
|
||||||
|
|
||||||
|
high_scores = relationship("HighScore", back_populates="owner")
|
||||||
|
course_progresses = relationship("CourseProgress", back_populates="owner")
|
||||||
|
|
||||||
|
|
||||||
|
class HighScore(Base):
|
||||||
|
__tablename__ = "high_scores"
|
||||||
|
|
||||||
|
high_score_id = Column(Integer, primary_key=True, index=True)
|
||||||
|
score_value = Column(Integer, nullable=False)
|
||||||
|
minigame = Column(Enum(MinigameEnum), nullable=False)
|
||||||
|
owner = Column(Integer, ForeignKey("users.user_id"))
|
||||||
|
|
||||||
|
|
||||||
|
class CourseProgress(Base):
|
||||||
|
__tablename__ = "course_progress"
|
||||||
|
|
||||||
|
course_progress_id = Column(Integer, primary_key=True, index=True)
|
||||||
|
course = Column(Enum(CourseEnum), nullable=False)
|
||||||
|
owner = Column(Integer, ForeignKey("users.user_id"))
|
||||||
|
|
||||||
Reference in New Issue
Block a user