kprofile_note.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. """Model for K-profile notes stored locally (not on printer)."""
  2. from datetime import datetime
  3. from sqlalchemy import String, Text, DateTime, ForeignKey, func, Index
  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(
  15. DateTime, server_default=func.now()
  16. )
  17. updated_at: Mapped[datetime] = mapped_column(
  18. DateTime, server_default=func.now(), onupdate=func.now()
  19. )
  20. # Relationship to printer
  21. printer: Mapped["Printer"] = relationship(back_populates="kprofile_notes")
  22. # Composite index for efficient lookups
  23. __table_args__ = (
  24. Index("ix_kprofile_notes_printer_setting", "printer_id", "setting_id", unique=True),
  25. )
  26. from backend.app.models.printer import Printer # noqa: E402