Fix an issue when a credential is deleted, resuming of download fails.

This commit is contained in:
Talmaj Marinc 2026-06-30 09:53:09 +02:00
parent e70f524d5f
commit 9c845eeb9e

View File

@ -65,7 +65,12 @@ class Download(Base):
expected_sha256: Mapped[str | None] = mapped_column(String(64), nullable=True)
# Explicit credential override; otherwise auto-resolved by host.
credential_id: Mapped[str | None] = mapped_column(String(36), nullable=True)
# RESTRICT keeps a credential from being deleted while a download references it.
credential_id: Mapped[str | None] = mapped_column(
String(36),
ForeignKey("host_credentials.id", ondelete="RESTRICT"),
nullable=True,
)
allow_any_extension: Mapped[bool] = mapped_column(
Boolean, nullable=False, default=False
)
@ -86,6 +91,10 @@ class Download(Base):
order_by="DownloadSegment.idx",
)
credential: Mapped[HostCredential | None] = relationship(
"HostCredential", back_populates="downloads"
)
__table_args__ = (
Index("ix_downloads_status", "status"),
Index("ix_downloads_priority", "priority"),
@ -152,6 +161,10 @@ class HostCredential(Base):
BigInteger, nullable=False, default=_now, onupdate=_now
)
downloads: Mapped[list[Download]] = relationship(
"Download", back_populates="credential"
)
__table_args__ = (
Index("uq_host_credentials_host", "host", unique=True),
)