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")
|