- Backend (FastAPI): - Attachment and AttachmentVersion models with migration - FileStorageService with SHA-256 checksum validation - File type validation (whitelist/blacklist) - Full CRUD API with version control support - Audit trail integration for upload/download/delete - Configurable upload directory and file size limit - Frontend (React + Vite): - AttachmentUpload component with drag & drop - AttachmentList component with download/delete - TaskAttachments combined component - Attachments service for API calls - Testing: - 12 tests for storage service and API endpoints - OpenSpec: - add-document-management change archived 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
32 lines
1.5 KiB
Python
32 lines
1.5 KiB
Python
import uuid
|
|
from sqlalchemy import Column, String, Text, Integer, BigInteger, Boolean, DateTime, ForeignKey, Index
|
|
from sqlalchemy.orm import relationship
|
|
from sqlalchemy.sql import func
|
|
from app.core.database import Base
|
|
|
|
|
|
class Attachment(Base):
|
|
__tablename__ = "pjctrl_attachments"
|
|
|
|
id = Column(String(36), primary_key=True, default=lambda: str(uuid.uuid4()))
|
|
task_id = Column(String(36), ForeignKey("pjctrl_tasks.id", ondelete="CASCADE"), nullable=False)
|
|
filename = Column(String(255), nullable=False)
|
|
original_filename = Column(String(255), nullable=False)
|
|
mime_type = Column(String(100), nullable=False)
|
|
file_size = Column(BigInteger, nullable=False)
|
|
current_version = Column(Integer, default=1, nullable=False)
|
|
is_encrypted = Column(Boolean, default=False, nullable=False)
|
|
uploaded_by = Column(String(36), ForeignKey("pjctrl_users.id", ondelete="SET NULL"), nullable=True)
|
|
is_deleted = Column(Boolean, default=False, nullable=False)
|
|
created_at = Column(DateTime, server_default=func.now(), nullable=False)
|
|
updated_at = Column(DateTime, server_default=func.now(), onupdate=func.now(), nullable=False)
|
|
|
|
# Relationships
|
|
task = relationship("Task", back_populates="attachments")
|
|
uploader = relationship("User", foreign_keys=[uploaded_by])
|
|
versions = relationship("AttachmentVersion", back_populates="attachment", cascade="all, delete-orphan")
|
|
|
|
__table_args__ = (
|
|
Index("idx_attachment_task", "task_id", "is_deleted"),
|
|
)
|