Skip to content

Commit

Permalink
Univeristy model (#83)
Browse files Browse the repository at this point in the history
* 3 New Files

Made GroupRun, TeamType, and University model files

* Added nullables

Added nullables to existing files

* Added unique

Added the unique constraint to team_type_name and uni_name.

* New things

Added some new files and foreign keys.

* Added new files

Added errors and turn table files.

* Fixes

Added fixes to all the files as needed.

* fixed?

* fixed again

* Small fix

Added Integer() to the primary key of the run file.

* Fixed

Fixed more Integer() that was missing.

---------

Co-authored-by: JuliaCaesar <[email protected]>
Co-authored-by: JuliaCaesar <[email protected]>
  • Loading branch information
3 people authored Sep 16, 2023
1 parent 4a09d04 commit a8fe6ee
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 0 deletions.
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)

0 comments on commit a8fe6ee

Please sign in to comment.