Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Univeristy model #83

Merged
merged 12 commits into from
Sep 16, 2023
12 changes: 12 additions & 0 deletions server/models/errors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from sqlalchemy import ForeignKey, Integer, String
from sqlalchemy.orm import Mapped, mapped_column

from server.models.base import Base


class Errors(Base):
__tablename__: str = 'errors'
error_id: Mapped[int] = mapped_column(Integer(), primary_key=True, autoincrement=True) # run id pk
run_id: Mapped[int] = mapped_column(Integer(), ForeignKey("run.run_id")) # run id
submission_id: Mapped[int] = mapped_column(Integer(), ForeignKey("submission.submission_id")) # submission id fk
error_txt: Mapped[str] = mapped_column(String(), nullable=True)
18 changes: 18 additions & 0 deletions server/models/group_run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from __future__ import annotations

from sqlalchemy import Boolean, Integer, String, DateTime
from sqlalchemy.orm import relationship, Mapped, mapped_column

from server.models.base import Base
from server.models.run import Run


class GroupRun(Base):
# Date times are stored in UTC in ISO format
__tablename__: str = 'group_run'
group_run_id: Mapped[int] = mapped_column(Integer(), primary_key=True, autoincrement=True)
start_run: Mapped[str] = mapped_column(DateTime(), nullable=False)
launcher_version: Mapped[str] = mapped_column(String(10), nullable=False)
runs_per_client: Mapped[int] = mapped_column(Integer(), nullable=False)
is_finished: Mapped[bool] = mapped_column(Boolean(), default=False, nullable=False)
runs: Mapped[list[Run]] = relationship()
18 changes: 18 additions & 0 deletions server/models/run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from sqlalchemy import LargeBinary, Boolean, ForeignKey, Integer, DateTime
from sqlalchemy.orm import Mapped, mapped_column

from server.models.base import Base


class Run(Base):
__tablename__: str = 'run'
run_id: Mapped[int] = mapped_column(Integer(), primary_key=True, autoincrement=True)
group_run_id: Mapped[int] = mapped_column(Integer(), ForeignKey("group_run.group_run_id"))
run_time: Mapped[str] = mapped_column(DateTime(), nullable=False)
winner: Mapped[bool] = mapped_column(Boolean(), nullable=False)
player_1: Mapped[int] = mapped_column(Integer(), nullable=False)
player_2: Mapped[int] = mapped_column(Integer(), nullable=False)
seed: Mapped[int] = mapped_column(Integer(), nullable=False)

# results is a JSON file that's read in, so it needs to be a LargeBinary object.
results: Mapped[str] = mapped_column(LargeBinary(), nullable=False)
12 changes: 12 additions & 0 deletions server/models/submission.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from sqlalchemy import LargeBinary, ForeignKey, Integer, DateTime
from sqlalchemy.orm import Mapped, mapped_column

from server.models.base import Base


class Submission(Base):
__tablename__: str = 'submission'
submission_id: Mapped[int] = mapped_column(Integer(), primary_key=True, autoincrement=True)
team_id_uuid: Mapped[int] = mapped_column(Integer(), ForeignKey("team.team_id_uuid"))
submission_time: Mapped[str] = mapped_column(DateTime(), nullable=False)
file_txt: Mapped[str] = mapped_column(LargeBinary(), nullable=False)
13 changes: 13 additions & 0 deletions server/models/team.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from sqlalchemy import CheckConstraint, ForeignKey, Integer, String
from sqlalchemy.orm import Mapped, mapped_column

from server.models.base import Base
from uuid import uuid4


class Team(Base):
__tablename__: str = 'team'
team_id_uuid: Mapped[int] = mapped_column(Integer(), primary_key=True, default=uuid4())
uni_id: Mapped[int] = mapped_column(Integer(), ForeignKey("university.uni_id"))
team_type_id: Mapped[int] = mapped_column(Integer(), ForeignKey("team_type.team_type_id"))
team_name: Mapped[str] = mapped_column(String(), CheckConstraint("team_name != ''"), unique=True, nullable=False)
12 changes: 12 additions & 0 deletions server/models/team_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from sqlalchemy import Integer, Boolean, CheckConstraint, String
from sqlalchemy.orm import Mapped, mapped_column

from server.models.base import Base


class TeamType(Base):
__tablename__: str = 'team_type'
team_type_id: Mapped[int] = mapped_column(Integer(), primary_key=True, autoincrement=True)
team_type_name: Mapped[str] = mapped_column(String(15), CheckConstraint("team_type_name != ''"), nullable=False,
unique=True)
eligible: bool = mapped_column(Boolean(), nullable=False)
14 changes: 14 additions & 0 deletions server/models/turn_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from sqlalchemy import LargeBinary, ForeignKey, Integer
from sqlalchemy.orm import Mapped, mapped_column

from server.models.base import Base


class TurnTable(Base):
__tablename__: str = 'turn_table'
turn_id: Mapped[int] = mapped_column(Integer(), primary_key=True)
turn_number: Mapped[int] = mapped_column(Integer())
run_id: Mapped[int] = mapped_column(Integer(), ForeignKey('run.run_id'))
turn_data: Mapped[str] = mapped_column(LargeBinary(), nullable=False)


10 changes: 10 additions & 0 deletions server/models/university.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from sqlalchemy import Integer, CheckConstraint, String
from sqlalchemy.orm import Mapped, mapped_column

from server.models.base import Base


class University(Base):
__tablename__: str = 'university'
uni_id: Mapped[int] = mapped_column(Integer(), primary_key=True, autoincrement=True)
uni_name: Mapped[str] = mapped_column(String(100), CheckConstraint("uni_name != ''"), nullable=False, unique=True)