Create queries table; set up cascade deletes
This commit is contained in:
parent
6792b2a628
commit
7a98fe3920
@ -79,6 +79,9 @@ class PlaylistsTable(Model):
|
|||||||
cascade="all, delete-orphan",
|
cascade="all, delete-orphan",
|
||||||
order_by="PlaylistRowsTable.row_number",
|
order_by="PlaylistRowsTable.row_number",
|
||||||
)
|
)
|
||||||
|
query: Mapped["QueriesTable"] = relationship(
|
||||||
|
back_populates="playlist", cascade="all, delete-orphan"
|
||||||
|
)
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
return (
|
return (
|
||||||
@ -95,7 +98,10 @@ class PlaylistRowsTable(Model):
|
|||||||
note: Mapped[str] = mapped_column(
|
note: Mapped[str] = mapped_column(
|
||||||
String(2048), index=False, default="", nullable=False
|
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")
|
playlist: Mapped[PlaylistsTable] = relationship(back_populates="rows")
|
||||||
track_id: Mapped[Optional[int]] = mapped_column(ForeignKey("tracks.id"))
|
track_id: Mapped[Optional[int]] = mapped_column(ForeignKey("tracks.id"))
|
||||||
track: Mapped["TracksTable"] = relationship(
|
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"<Queries(id={self.id}, playlist={self.playlist}, query={self.query}>"
|
||||||
|
|
||||||
|
|
||||||
class SettingsTable(Model):
|
class SettingsTable(Model):
|
||||||
"""Manage settings"""
|
"""Manage settings"""
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user