Files
flask-formula10/formula10/database/model/db_driver.py
Christoph Urlacher d3097038a5
All checks were successful
Build Formula10 Docker Image / build-docker (push) Successful in 15s
Large database migration
2024-03-03 15:38:35 +01:00

25 lines
918 B
Python

from sqlalchemy import Integer, String, ForeignKey
from sqlalchemy.orm import mapped_column, Mapped, relationship
from formula10.database.model.db_team import DbTeam
from formula10 import db
class DbDriver(db.Model):
"""
A F1 driver.
It stores the corresponding team + name abbreviation.
"""
__tablename__ = "driver"
def __init__(self, *, id: int):
self.id = id # Primary key
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=False)
name: Mapped[str] = mapped_column(String(32), nullable=False, unique=True)
abbr: Mapped[str] = mapped_column(String(4), nullable=False, unique=True)
team_id: Mapped[str] = mapped_column(ForeignKey("team.id"), nullable=False)
country_code: Mapped[str] = mapped_column(String(2), nullable=False) # alpha-2 code
# Relationships
team: Mapped[DbTeam] = relationship("DbTeam", foreign_keys=[team_id])