9eb1614fbf
Adds Tag.kind enum (artist/character/fandom/general/series/archive/post/meta/rating), Tag.fandom_id FK with CHECK constraint (only valid for kind='character'), and a kind-aware uniqueness index so the same name can exist across kinds and the same character name can exist in different fandoms. Adds ImportBatch + ImportTask state-machine tables for scan tracking, plus a single-row ImportSettings table (CHECK id=1) holding the importer's filter knobs. Adds image_record.integrity_status column (defaults to 'unknown'); FC-2e populates this via the integrity verifier. Drops the unused tag.namespace column from FC-1 — superseded by kind. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
33 lines
1.3 KiB
Python
33 lines
1.3 KiB
Python
"""ImportBatch — one scan run, aggregating many ImportTasks."""
|
|
|
|
from datetime import datetime
|
|
|
|
from sqlalchemy import DateTime, Integer, String, Text, func
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from .base import Base
|
|
|
|
|
|
class ImportBatch(Base):
|
|
__tablename__ = "import_batch"
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
|
triggered_by: Mapped[str] = mapped_column(String(32), nullable=False)
|
|
source_path: Mapped[str] = mapped_column(Text, nullable=False)
|
|
scan_mode: Mapped[str] = mapped_column(String(16), nullable=False) # quick|deep
|
|
|
|
started_at: Mapped[datetime] = mapped_column(
|
|
DateTime(timezone=True), nullable=False, server_default=func.now()
|
|
)
|
|
finished_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True)
|
|
|
|
total_files: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
|
|
imported: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
|
|
skipped: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
|
|
failed: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
|
|
|
|
status: Mapped[str] = mapped_column(String(16), nullable=False, default="running", index=True)
|
|
# running | complete | cancelled
|
|
|
|
tasks = relationship("ImportTask", back_populates="batch", cascade="all, delete-orphan")
|