| from __future__ import annotations |
|
|
| from datetime import datetime, timezone |
|
|
| from sqlalchemy import DateTime, Enum as SAEnum, Integer, String, Text, func |
| from sqlalchemy.orm import Mapped, mapped_column |
|
|
| from .base import Base, DatasetType |
|
|
|
|
| class Dataset(Base): |
| """A batch-loaded collection of dogs/users (test fixtures or real imports). |
| |
| Existing tables carry a nullable ``dataset_id`` back to here so a whole batch can be listed, |
| inspected, and purged as a unit. Cases/matches are linked transitively through the dogs/users |
| and are removed by the transactional purge endpoint (see api/datasets.py). |
| """ |
|
|
| __tablename__ = "datasets" |
|
|
| id: Mapped[int] = mapped_column(primary_key=True) |
| name: Mapped[str] = mapped_column(String(160)) |
| type: Mapped[DatasetType] = mapped_column(SAEnum(DatasetType, native_enum=False)) |
| description: Mapped[str | None] = mapped_column(Text, nullable=True) |
| source_path: Mapped[str | None] = mapped_column(String(512), nullable=True) |
| dog_count: Mapped[int] = mapped_column(Integer, default=0) |
| creation_time: Mapped[datetime] = mapped_column( |
| DateTime(timezone=True), |
| default=lambda: datetime.now(timezone.utc), |
| server_default=func.now(), |
| ) |
|
|