This repository has been archived by the owner on Sep 6, 2024. It is now read-only.
generated from python-discord/code-jam-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d0f53b5
commit 8c55464
Showing
7 changed files
with
120 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from sqlalchemy import ForeignKey | ||
from sqlalchemy.orm import Mapped, mapped_column | ||
|
||
# Prevent circular imports for relationships | ||
|
||
|
||
class Media: | ||
"""Represents a media object in the database. DO NOT USE DIRECTLY.""" | ||
|
||
id: Mapped[int] = mapped_column(primary_key=True, index=True, nullable=False) | ||
|
||
favorite: Mapped[bool] = mapped_column(default=False) | ||
watched: Mapped[bool] = mapped_column(default=False) | ||
|
||
user_id: Mapped[int] = mapped_column(ForeignKey("user.id"), nullable=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from typing import TYPE_CHECKING | ||
|
||
from sqlalchemy import ForeignKey | ||
from sqlalchemy.orm import Mapped, mapped_column, relationship | ||
|
||
from src.utils.database import Base | ||
|
||
# Prevent circular imports for relationships | ||
if TYPE_CHECKING: | ||
from src.db_tables.show import Show | ||
from src.db_tables.user import User | ||
|
||
|
||
class Episode(Base): | ||
"""User database table.""" | ||
|
||
__tablename__ = "episode" | ||
|
||
id: Mapped[int] = mapped_column(primary_key=True, index=True, nullable=False) | ||
|
||
show_id: Mapped[int] = mapped_column(ForeignKey("user.id"), nullable=False) | ||
tvdb_id: Mapped[int] = mapped_column(nullable=False) | ||
|
||
show: Mapped["Show"] = relationship(lazy="selectin", back_populates="episodes") | ||
user: Mapped["User"] = relationship(lazy="selectin", back_populates="shows") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from typing import TYPE_CHECKING | ||
|
||
from sqlalchemy.orm import Mapped, mapped_column, relationship | ||
|
||
from src.db_tables._media import Media | ||
from src.utils.database import Base | ||
|
||
if TYPE_CHECKING: | ||
from src.db_tables.user import User | ||
|
||
|
||
class Movie(Media, Base): | ||
"""User database table.""" | ||
|
||
user: Mapped["User"] = relationship(lazy="selectin", back_populates="movies") | ||
tvdb_id: Mapped[int] = mapped_column(nullable=False) | ||
__tablename__ = "movie" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from typing import TYPE_CHECKING | ||
|
||
from sqlalchemy.orm import Mapped, mapped_column, relationship | ||
|
||
from src.db_tables._media import Media | ||
from src.utils.database import Base | ||
|
||
if TYPE_CHECKING: | ||
from src.db_tables.episode import Episode | ||
from src.db_tables.user import User | ||
|
||
|
||
class Show(Media, Base): | ||
"""User database table.""" | ||
|
||
__tablename__ = "show" | ||
|
||
user: Mapped["User"] = relationship(lazy="selectin", back_populates="shows") | ||
tvdb_id: Mapped[int] = mapped_column(nullable=False) | ||
|
||
# contains episodes whose watch state is different from the show's | ||
episodes: Mapped[list["Episode"]] = relationship( | ||
lazy="selectin", | ||
back_populates="show", | ||
cascade="all, delete-orphan", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from typing import TYPE_CHECKING | ||
|
||
from sqlalchemy.orm import Mapped, mapped_column, relationship | ||
|
||
from src.utils.database import Base | ||
|
||
# Prevent circular imports for relationships | ||
if TYPE_CHECKING: | ||
from src.db_tables.movie import Movie | ||
from src.db_tables.show import Show | ||
|
||
|
||
class User(Base): | ||
"""User database table.""" | ||
|
||
__tablename__ = "user" | ||
|
||
id: Mapped[int] = mapped_column(primary_key=True, index=True, nullable=False) | ||
|
||
shows: Mapped[list["Show"]] = relationship( | ||
lazy="selectin", | ||
back_populates="user", | ||
cascade="all, delete-orphan", | ||
) | ||
|
||
movies: Mapped[list["Movie"]] = relationship( | ||
lazy="selectin", | ||
back_populates="user", | ||
cascade="all, delete-orphan", | ||
) |