62 lines
2.3 KiB
Python
62 lines
2.3 KiB
Python
"""
|
|
Attachment Model - ServiceManagerWeb
|
|
"""
|
|
from sqlalchemy import String, ForeignKey, Integer, DateTime, func
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
from typing import Optional, TYPE_CHECKING
|
|
from datetime import datetime
|
|
import uuid
|
|
|
|
from app.core.database import Base, GUID
|
|
|
|
if TYPE_CHECKING:
|
|
from app.models.ticket import Ticket
|
|
from app.models.comment import TicketComment
|
|
from app.models.user import User
|
|
|
|
|
|
class TicketAttachment(Base):
|
|
"""Modelo de archivos adjuntos en tickets"""
|
|
__tablename__ = "ticket_attachments"
|
|
|
|
# Sobrescribir campos heredados de Base para que coincidan con la tabla real
|
|
id: Mapped[uuid.UUID] = mapped_column(GUID(), primary_key=True, default=uuid.uuid4)
|
|
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())
|
|
# Esta tabla NO tiene updated_at, así que lo excluimos del mapping
|
|
|
|
ticket_id: Mapped[uuid.UUID] = mapped_column(
|
|
GUID(),
|
|
ForeignKey("tickets.id", ondelete="CASCADE"),
|
|
nullable=False
|
|
)
|
|
|
|
comment_id: Mapped[Optional[uuid.UUID]] = mapped_column(
|
|
GUID(),
|
|
ForeignKey("ticket_comments.id", ondelete="CASCADE"),
|
|
nullable=True
|
|
)
|
|
|
|
uploaded_by: Mapped[uuid.UUID] = mapped_column(
|
|
GUID(),
|
|
ForeignKey("users.id"),
|
|
nullable=False
|
|
)
|
|
|
|
filename: Mapped[str] = mapped_column(String(255), nullable=False)
|
|
original_filename: Mapped[str] = mapped_column(String(255), nullable=False)
|
|
mime_type: Mapped[str] = mapped_column(String(100), nullable=False)
|
|
file_size: Mapped[int] = mapped_column(Integer, nullable=False)
|
|
file_path: Mapped[str] = mapped_column(String(500), nullable=False)
|
|
|
|
md5_hash: Mapped[Optional[str]] = mapped_column(String(32), nullable=True)
|
|
sha256_hash: Mapped[Optional[str]] = mapped_column(String(64), nullable=True)
|
|
|
|
ticket: Mapped["Ticket"] = relationship("Ticket", back_populates="attachments")
|
|
comment: Mapped[Optional["TicketComment"]] = relationship("TicketComment", back_populates="attachments")
|
|
uploaded_by_user: Mapped["User"] = relationship("User")
|
|
|
|
# Excluir updated_at del mapping ya que la tabla no lo tiene
|
|
__mapper_args__ = {
|
|
"exclude_properties": ["updated_at"]
|
|
}
|