From b7dc05b7ee27edbbacd4e20705c62f37ca0ed4a5 Mon Sep 17 00:00:00 2001 From: Leopoldadmin Date: Sat, 4 Jul 2026 00:29:11 +0000 Subject: [PATCH] feat(core): add Attachment model --- app/models/attachment.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 app/models/attachment.py diff --git a/app/models/attachment.py b/app/models/attachment.py new file mode 100644 index 0000000..3ba3797 --- /dev/null +++ b/app/models/attachment.py @@ -0,0 +1,35 @@ +"""Attachment model — file attachments for any entity.""" + +from __future__ import annotations + +import uuid +from datetime import datetime + +from sqlalchemy import DateTime, ForeignKey, Index, Integer, String +from sqlalchemy.dialects.postgresql import UUID as PGUUID +from sqlalchemy.orm import Mapped, mapped_column + +from app.core.db import Base, TenantMixin + + +class Attachment(Base, TenantMixin): + """Attachment entity — links files to companies, contacts, invoices, etc.""" + + __tablename__ = "attachments" + __table_args__ = ( + Index("ix_attachments_entity", "entity_type", "entity_id", "tenant_id"), + ) + + id: Mapped[uuid.UUID] = mapped_column( + PGUUID(as_uuid=True), primary_key=True, default=uuid.uuid4 + ) + entity_type: Mapped[str] = mapped_column(String(50), nullable=False) + entity_id: Mapped[uuid.UUID] = mapped_column(PGUUID(as_uuid=True), nullable=False) + filename: Mapped[str] = mapped_column(String(255), nullable=False) + file_path: Mapped[str] = mapped_column(String(500), nullable=False) + mime_type: Mapped[str] = mapped_column(String(100), nullable=False, default="application/octet-stream") + file_size: Mapped[int] = mapped_column(Integer, nullable=False, default=0) + uploaded_by: Mapped[uuid.UUID | None] = mapped_column( + PGUUID(as_uuid=True), ForeignKey("users.id", ondelete="SET NULL"), nullable=True + ) + deleted_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True)