diff --git a/server/models/errors.py b/server/models/errors.py new file mode 100644 index 0000000..702a03a --- /dev/null +++ b/server/models/errors.py @@ -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) diff --git a/server/models/group_run.py b/server/models/group_run.py new file mode 100644 index 0000000..58f8343 --- /dev/null +++ b/server/models/group_run.py @@ -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() diff --git a/server/models/run.py b/server/models/run.py new file mode 100644 index 0000000..7249f97 --- /dev/null +++ b/server/models/run.py @@ -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) diff --git a/server/models/submission.py b/server/models/submission.py new file mode 100644 index 0000000..47af5d9 --- /dev/null +++ b/server/models/submission.py @@ -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) diff --git a/server/models/team.py b/server/models/team.py new file mode 100644 index 0000000..057f6df --- /dev/null +++ b/server/models/team.py @@ -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) diff --git a/server/models/team_type.py b/server/models/team_type.py new file mode 100644 index 0000000..4840aaa --- /dev/null +++ b/server/models/team_type.py @@ -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) diff --git a/server/models/turn_table.py b/server/models/turn_table.py new file mode 100644 index 0000000..b4f577c --- /dev/null +++ b/server/models/turn_table.py @@ -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) + + diff --git a/server/models/university.py b/server/models/university.py new file mode 100644 index 0000000..59d346d --- /dev/null +++ b/server/models/university.py @@ -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)