34d30e3134
Media model + migration; an ObjectStore interface with an S3/MinIO (boto3) implementation behind the service layer. Upload (multipart) stores bytes in object storage + a metadata row (checksum, size, content-type, optional attach to person/event/source); list returns presigned URLs; delete is soft. Editor-gated, privacy-filtered, audited. 24 tests pass (object store faked). Introduces the worker container (same image, 'python -m app.worker'): its first job is the scheduled 30-day soft-delete purge across tables + media object cleanup. Compose gains worker + S3 env on backend/worker; dev override builds the worker too. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Justin Paul <justin@jpaul.me>
37 lines
1.5 KiB
Python
37 lines
1.5 KiB
Python
"""Media — a binary asset (image, scan, PDF, audio) in object storage. The row
|
|
holds metadata + checksum + the storage key; the bytes live in the ObjectStore.
|
|
Optionally attached to a single fact (person, event, or source) for now."""
|
|
|
|
import uuid
|
|
|
|
from sqlalchemy import BigInteger, ForeignKey, String
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from app.models.base import Base
|
|
from app.models.mixins import SoftDelete, TenantScoped, Timestamps, UUIDPrimaryKey
|
|
|
|
|
|
class Media(Base, UUIDPrimaryKey, TenantScoped, Timestamps, SoftDelete):
|
|
__tablename__ = "media"
|
|
|
|
uploader_id: Mapped[uuid.UUID | None] = mapped_column(
|
|
ForeignKey("users.id", ondelete="SET NULL"), index=True
|
|
)
|
|
storage_key: Mapped[str] = mapped_column(String(512), unique=True)
|
|
original_filename: Mapped[str] = mapped_column(String(512))
|
|
content_type: Mapped[str] = mapped_column(String(128))
|
|
byte_size: Mapped[int] = mapped_column(BigInteger)
|
|
checksum_sha256: Mapped[str] = mapped_column(String(64), index=True)
|
|
title: Mapped[str | None] = mapped_column(String(512))
|
|
|
|
# Optional single attachment target.
|
|
person_id: Mapped[uuid.UUID | None] = mapped_column(
|
|
ForeignKey("persons.id", ondelete="SET NULL"), index=True
|
|
)
|
|
event_id: Mapped[uuid.UUID | None] = mapped_column(
|
|
ForeignKey("events.id", ondelete="SET NULL"), index=True
|
|
)
|
|
source_id: Mapped[uuid.UUID | None] = mapped_column(
|
|
ForeignKey("sources.id", ondelete="SET NULL"), index=True
|
|
)
|