kprofile_note.py 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. """Model for K-profile notes stored locally (not on printer)."""
  2. from datetime import datetime
  3. from sqlalchemy import DateTime, ForeignKey, Index, String, Text, func
  4. from sqlalchemy.orm import Mapped, mapped_column, relationship
  5. from backend.app.core.database import Base
  6. class KProfileNote(Base):
  7. """Notes for K-profiles stored locally since printers don't support notes."""
  8. __tablename__ = "kprofile_notes"
  9. id: Mapped[int] = mapped_column(primary_key=True)
  10. printer_id: Mapped[int] = mapped_column(ForeignKey("printers.id", ondelete="CASCADE"))
  11. # setting_id is the unique identifier for a K-profile on the printer
  12. setting_id: Mapped[str] = mapped_column(String(100))
  13. note: Mapped[str] = mapped_column(Text, default="")
  14. created_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now())
  15. updated_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now(), onupdate=func.now())
  16. # Relationship to printer
  17. printer: Mapped["Printer"] = relationship(back_populates="kprofile_notes")
  18. # Composite index for efficient lookups
  19. __table_args__ = (Index("ix_kprofile_notes_printer_setting", "printer_id", "setting_id", unique=True),)
  20. from backend.app.models.printer import Printer # noqa: E402