diff --git a/app/dbtables.py b/app/dbtables.py index 808c301..c12b8cc 100644 --- a/app/dbtables.py +++ b/app/dbtables.py @@ -79,6 +79,9 @@ class PlaylistsTable(Model): cascade="all, delete-orphan", order_by="PlaylistRowsTable.row_number", ) + query: Mapped["QueriesTable"] = relationship( + back_populates="playlist", cascade="all, delete-orphan" + ) def __repr__(self) -> str: return ( @@ -95,7 +98,10 @@ class PlaylistRowsTable(Model): note: Mapped[str] = mapped_column( String(2048), index=False, default="", nullable=False ) - playlist_id: Mapped[int] = mapped_column(ForeignKey("playlists.id"), index=True) + playlist_id: Mapped[int] = mapped_column( + ForeignKey("playlists.id", ondelete="CASCADE"), index=True + ) + playlist: Mapped[PlaylistsTable] = relationship(back_populates="rows") track_id: Mapped[Optional[int]] = mapped_column(ForeignKey("tracks.id")) track: Mapped["TracksTable"] = relationship( @@ -114,6 +120,20 @@ class PlaylistRowsTable(Model): ) +class QueriesTable(Model): + __tablename__ = "queries" + + id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True) + query: Mapped[str] = mapped_column( + String(2048), index=False, default="", nullable=False + ) + playlist_id: Mapped[int] = mapped_column(ForeignKey("playlists.id"), index=True) + playlist: Mapped[PlaylistsTable] = relationship(back_populates="query") + + def __repr__(self) -> str: + return f"" + + class SettingsTable(Model): """Manage settings"""