diff --git a/app/db/models.py b/app/db/models.py index 12884e3..08d6827 100644 --- a/app/db/models.py +++ b/app/db/models.py @@ -1,7 +1,7 @@ from datetime import datetime, timezone from uuid import UUID, uuid4 -from sqlalchemy import DateTime, ForeignKey, Index, String, Text +from sqlalchemy import DateTime, ForeignKey, Index, Integer, String, Text from sqlalchemy.dialects.postgresql import UUID as PG_UUID from sqlalchemy.orm import Mapped, mapped_column from sqlalchemy import UniqueConstraint @@ -112,4 +112,23 @@ class IdempotencyRecord(Base): __table_args__ = ( UniqueConstraint("user_id", "key", name="uq_idempotency_user_key"), - ) \ No newline at end of file + ) + +class Attachment(Base): + __tablename__ = "attachments" + id: Mapped[UUID] = mapped_column(PG_UUID(as_uuid=True), primary_key=True, default=uuid4) + chat_id: Mapped[UUID] = mapped_column(PG_UUID(as_uuid=True), ForeignKey("chats.id", ondelete="CASCADE"), nullable=False) + owner_id: Mapped[UUID] = mapped_column(PG_UUID(as_uuid=True), ForeignKey("users.id"), nullable=False) + filename: Mapped[str] = mapped_column(String(255), nullable=False) + content_type: Mapped[str] = mapped_column(String(100), nullable=False) + size_bytes: Mapped[int] = mapped_column(Integer, nullable=False) + sha256: Mapped[str] = mapped_column(String(64), nullable=False) + status: Mapped[str] = mapped_column(String(20), default="ready", nullable=False) + error_code: Mapped[str] = mapped_column(String(50), nullable=True) + s3_key: Mapped[str] = mapped_column(String(500), nullable=False) + created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=lambda: datetime.now(timezone.utc), nullable=False) + +class MessageAttachment(Base): + __tablename__ = "message_attachments" + message_id: Mapped[UUID] = mapped_column(PG_UUID(as_uuid=True), ForeignKey("messages.id", ondelete="CASCADE"), primary_key=True) + attachment_id: Mapped[UUID] = mapped_column(PG_UUID(as_uuid=True), ForeignKey("attachments.id", ondelete="CASCADE"), primary_key=True) \ No newline at end of file diff --git a/app/models.py b/app/models.py index 19dc859..e98a1a9 100644 --- a/app/models.py +++ b/app/models.py @@ -53,4 +53,22 @@ class SessionResponse(BaseModel): token: str token_type: str = "Bearer" expires_at: str - user: dict \ No newline at end of file + user: dict + +class AttachmentResponse(BaseModel): + model_config = ConfigDict(extra="forbid") + id: UUID + chat_id: UUID + owner_id: UUID + filename: str + content_type: str + size_bytes: int + sha256: str + status: str + error_code: str | None = None + created_at: str + +class CreateMessage(BaseModel): + model_config = ConfigDict(extra="forbid") + text: str = Field(min_length=1, max_length=4000) + attachment_ids: list[UUID] | None = None \ No newline at end of file