Files
saas_backend/app/models/system/document_model.py
T

35 lines
1.3 KiB
Python
Raw Normal View History

2026-08-31 20:04:12 -04:00
"""A file attached to something."""
from __future__ import annotations
from sqlalchemy import BigInteger, Column, DateTime, ForeignKey, String, func
from sqlalchemy.dialects.postgresql import UUID
from app.config.database import Base
class Document(Base):
__tablename__ = "documents"
id = Column(UUID(as_uuid=True), primary_key=True,
server_default=func.gen_random_uuid())
tenant_id = Column(UUID(as_uuid=True), ForeignKey("tenants.id", ondelete="CASCADE"),
nullable=False)
uploaded_by_id = Column(UUID(as_uuid=True),
ForeignKey("users.id", ondelete="SET NULL"))
entity_type = Column(String(60))
entity_id = Column(String(64))
filename = Column(String(255), nullable=False)
content_type = Column(String(120), nullable=False)
size_bytes = Column(BigInteger, nullable=False)
checksum = Column(String(64), nullable=False)
storage_key = Column(String(120), nullable=False)
description = Column(String(500))
deleted_at = Column(DateTime(timezone=True))
deleted_by_id = Column(UUID(as_uuid=True))
created_at = Column(DateTime(timezone=True), nullable=False, server_default=func.now())
@property
def is_deleted(self) -> bool:
return self.deleted_at is not None