86 lines
2.1 KiB
Python
86 lines
2.1 KiB
Python
from datetime import datetime
|
|
|
|
from sqlalchemy import ForeignKey, func, Integer, Boolean, String, Text, DateTime
|
|
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column, relationship
|
|
|
|
|
|
class Base(DeclarativeBase):
|
|
"""Base déclarative pour SQLAlchemy 2.0."""
|
|
pass
|
|
|
|
|
|
class TvShowDB(Base):
|
|
"""Modèle pour le stockage des épisodes (SQLAlchemy 2.0)."""
|
|
|
|
__tablename__: str = "tvshows"
|
|
|
|
id: Mapped[int] = mapped_column(
|
|
Integer,
|
|
primary_key=True,
|
|
autoincrement=True
|
|
)
|
|
post_id: Mapped[str] = mapped_column(
|
|
String(length=255),
|
|
nullable=False,
|
|
unique=True,
|
|
index=True
|
|
)
|
|
post_title: Mapped[str] = mapped_column(
|
|
String(255),
|
|
nullable=False
|
|
)
|
|
title: Mapped[str] = mapped_column(
|
|
String(255),
|
|
nullable=False,
|
|
index=True
|
|
)
|
|
date: Mapped[datetime] = mapped_column(
|
|
DateTime,
|
|
nullable=False,
|
|
index=True
|
|
)
|
|
summary: Mapped[str | None] = mapped_column(
|
|
Text,
|
|
nullable=True
|
|
)
|
|
image_url: Mapped[str | None] = mapped_column(
|
|
String(255),
|
|
nullable=True
|
|
)
|
|
created_at: Mapped[datetime] = mapped_column(
|
|
DateTime,
|
|
server_default=func.datetime('now'),
|
|
nullable=False
|
|
)
|
|
updated_at: Mapped[datetime] = mapped_column(
|
|
DateTime,
|
|
server_default=func.datetime('now'),
|
|
onupdate=func.datetime('now'),
|
|
nullable=False
|
|
)
|
|
links: Mapped[list["LinkDB"]] = relationship(back_populates="show")
|
|
|
|
|
|
class LinkDB(Base):
|
|
"""Modèle pour le stockage des liens de téléchargement (SQLAlchemy 2.0)."""
|
|
|
|
__tablename__: str = "links"
|
|
|
|
id: Mapped[int] = mapped_column(
|
|
Integer,
|
|
primary_key=True,
|
|
autoincrement=True
|
|
)
|
|
link: Mapped[str] = mapped_column(
|
|
String(255),
|
|
nullable=False
|
|
)
|
|
is_downloaded: Mapped[bool] = mapped_column(
|
|
Boolean,
|
|
default=False
|
|
)
|
|
show_id: Mapped[int] = mapped_column(ForeignKey("tvshows.id"))
|
|
show: Mapped["TvShowDB"] = relationship(back_populates="links")
|
|
|
|
|