Complete Non-Conformance Report system replacing the PowerApps/SharePoint prototype: FastAPI + SQLAlchemy 2 (async) + Alembic + MySQL 8 backend, React 18 + Vite + TypeScript + MUI frontend, Entra ID auth (MSAL / JWKS, group-gated), Microsoft Graph delegated Mail.Send notifications (OBO), six-stage workflow state machine with server-side enforcement, atomic NCR-YYYY-NNNN numbering, attachments with camera capture, immutable field-level audit trail, admin reopen, reports + CSV export, WeasyPrint PDF traveler, Power BI reporting views + read-only DB user, documented VISUAL ERP job-lookup stub, pytest suite (26 tests), docker-compose deployment. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
26 lines
1.1 KiB
Python
26 lines
1.1 KiB
Python
from datetime import datetime
|
|
|
|
from sqlalchemy import BigInteger, Boolean, DateTime, ForeignKey, String
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from app.models.base import Base, utcnow
|
|
from app.models.user import User
|
|
|
|
|
|
class Attachment(Base):
|
|
__tablename__ = "attachments"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
|
ncr_id: Mapped[int] = mapped_column(ForeignKey("ncrs.id", ondelete="CASCADE"))
|
|
original_filename: Mapped[str] = mapped_column(String(255))
|
|
# Relative path under ATTACHMENTS_DIR: "<ncr_id>/<uuid><ext>"
|
|
stored_path: Mapped[str] = mapped_column(String(300), unique=True)
|
|
content_type: Mapped[str] = mapped_column(String(100))
|
|
size_bytes: Mapped[int] = mapped_column(BigInteger)
|
|
is_image: Mapped[bool] = mapped_column(Boolean, default=False)
|
|
uploaded_by_id: Mapped[int] = mapped_column(ForeignKey("users.id"))
|
|
uploaded_at: Mapped[datetime] = mapped_column(DateTime, default=utcnow)
|
|
|
|
ncr = relationship("Ncr", back_populates="attachments")
|
|
uploaded_by: Mapped[User] = relationship(lazy="selectin")
|