75 lines
2.0 KiB
Python
75 lines
2.0 KiB
Python
from datetime import datetime, timezone
|
|
from sqlmodel import (
|
|
ARRAY,
|
|
Column,
|
|
Relationship,
|
|
SQLModel,
|
|
Field,
|
|
create_engine,
|
|
String,
|
|
)
|
|
|
|
with open("db.secrets", "r") as f:
|
|
db_secrets = f.readline().strip()
|
|
|
|
engine = create_engine(db_secrets)
|
|
del db_secrets
|
|
|
|
|
|
def utctime():
|
|
return datetime.now(tz=timezone.utc)
|
|
|
|
|
|
class PlayerTeamLink(SQLModel, table=True):
|
|
team_id: int | None = Field(default=None, foreign_key="team.id", primary_key=True)
|
|
player_id: int | None = Field(
|
|
default=None, foreign_key="player.id", primary_key=True
|
|
)
|
|
|
|
|
|
class Team(SQLModel, table=True):
|
|
id: int | None = Field(default=None, primary_key=True)
|
|
name: str
|
|
location: str | None
|
|
country: str | None
|
|
players: list["Player"] | None = Relationship(
|
|
back_populates="teams", link_model=PlayerTeamLink
|
|
)
|
|
|
|
|
|
class Player(SQLModel, table=True):
|
|
id: int | None = Field(default=None, primary_key=True)
|
|
name: str
|
|
number: str | None = None
|
|
teams: list[Team] | None = Relationship(
|
|
back_populates="players", link_model=PlayerTeamLink
|
|
)
|
|
|
|
|
|
class Chemistry(SQLModel, table=True):
|
|
id: int | None = Field(default=None, primary_key=True)
|
|
time: datetime | None = Field(default_factory=utctime)
|
|
user: str
|
|
love: list[str] = Field(sa_column=Column(ARRAY(String)))
|
|
hate: list[str] = Field(sa_column=Column(ARRAY(String)))
|
|
undecided: list[str] = Field(sa_column=Column(ARRAY(String)))
|
|
|
|
|
|
class MVPRanking(SQLModel, table=True):
|
|
id: int | None = Field(default=None, primary_key=True)
|
|
time: datetime | None = Field(default_factory=utctime)
|
|
user: str
|
|
mvps: list[str] = Field(sa_column=Column(ARRAY(String)))
|
|
|
|
|
|
class User(SQLModel, table=True):
|
|
username: str = Field(default=None, primary_key=True)
|
|
email: str | None = None
|
|
full_name: str | None = None
|
|
disabled: bool | None = None
|
|
hashed_password: str | None = None
|
|
player_id: int | None = Field(default=None, foreign_key="player.id")
|
|
|
|
|
|
SQLModel.metadata.create_all(engine)
|