from __future__ import annotations from datetime import datetime from uuid import UUID from sqlalchemy import BigInteger, DateTime, ForeignKey, Index, Integer, String, UniqueConstraint from sqlalchemy.orm import Mapped, mapped_column from sqlalchemy.types import Uuid from ..db.postgres import Base class AttachmentRow(Base): __tablename__ = 'attachments' __table_args__ = ( Index('attachments_chat_created_idx', 'chat_id', 'created_at', 'id'), UniqueConstraint('object_key', name='attachments_object_key_key'), ) id: Mapped[UUID] = mapped_column(Uuid, primary_key=True) chat_id: Mapped[UUID] = mapped_column(ForeignKey('chats.id', ondelete='CASCADE'), nullable=False) owner_id: Mapped[UUID] = mapped_column(ForeignKey('users.id'), nullable=False) filename: Mapped[str] = mapped_column(String(255), nullable=False) object_key: Mapped[str] = mapped_column(String(255), nullable=False) content_type: Mapped[str] = mapped_column(String(32), nullable=False) size_bytes: Mapped[int] = mapped_column(BigInteger, nullable=False) sha256: Mapped[str] = mapped_column(String(64), nullable=False) width: Mapped[int] = mapped_column(Integer, nullable=False) height: Mapped[int] = mapped_column(Integer, nullable=False) status: Mapped[str] = mapped_column(String(16), nullable=False) error_code: Mapped[str | None] = mapped_column(String(64), nullable=True) created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), nullable=False) updated_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), nullable=False) class MessageAttachmentRow(Base): __tablename__ = 'message_attachments' __table_args__ = ( UniqueConstraint('message_id', 'position', name='message_attachments_message_position_key'), Index('message_attachments_attachment_idx', 'attachment_id'), ) message_id: Mapped[UUID] = mapped_column( ForeignKey('messages.id', ondelete='CASCADE'), primary_key=True ) attachment_id: Mapped[UUID] = mapped_column( ForeignKey('attachments.id', ondelete='CASCADE'), primary_key=True ) position: Mapped[int] = mapped_column(Integer, nullable=False)