32 lines
1,016 B
Python
32 lines
1,016 B
Python
"""AnnotationState model — current working annotation layer per document."""
|
|
|
|
from datetime import datetime, timezone
|
|
|
|
from sqlalchemy import ForeignKey, Text
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from app.db import Base
|
|
|
|
|
|
def _now_iso() -> str:
|
|
return datetime.now(timezone.utc).isoformat()
|
|
|
|
|
|
class AnnotationState(Base):
|
|
"""
|
|
Current working annotation state for a document.
|
|
|
|
One row per document. `data` is a JSON text column containing
|
|
the full annotation array — opaque to the server except during export.
|
|
"""
|
|
|
|
__tablename__ = "annotation_states"
|
|
|
|
document_id: Mapped[str] = mapped_column(
|
|
Text, ForeignKey("documents.id", ondelete="CASCADE"), primary_key=True
|
|
)
|
|
data: Mapped[str] = mapped_column(Text, default="[]") # JSON array
|
|
updated_at: Mapped[str] = mapped_column(Text, default=_now_iso, onupdate=_now_iso)
|
|
|
|
# Relationships
|
|
document: Mapped["Document"] = relationship("Document", back_populates="annotation_state")
|