archive_alias.py 1.1 KB

12345678910111213141516171819202122232425
  1. from datetime import datetime
  2. from sqlalchemy import DateTime, ForeignKey, Integer, func
  3. from sqlalchemy.orm import Mapped, mapped_column
  4. from backend.app.core.database import Base
  5. class ArchiveAlias(Base):
  6. """An archive merged into another (archive redesign P2): its id still
  7. finds the archive it went into, so old links, bookmarks and API calls
  8. keep working. The merged row stays, soft-deleted, so the money booked
  9. against it (wallet charges, budget reservations) is never rewritten.
  10. Flattened: an archive merged on later passes its aliases to the one it
  11. went into, so an id resolves in one step.
  12. """
  13. __tablename__ = "archive_aliases"
  14. # The merged archive's id. Not a foreign key: the merged row may be purged
  15. # with the other soft-deleted archives, and its id must keep resolving.
  16. merged_archive_id: Mapped[int] = mapped_column(Integer, primary_key=True)
  17. archive_id: Mapped[int] = mapped_column(ForeignKey("print_archives.id", ondelete="CASCADE"), index=True)
  18. merged_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now())