Scaffold SQLAlchemy models, routers, and Alembic migrations
- app/models/: Printer, Filament, PrintJob, Todo, PricingConfig with full SQLAlchemy 2.x mapped columns and relationships - app/routers/: list + get-by-id endpoints for all five resources - app/db.py: SQLAlchemy engine + SessionLocal + get_db dependency - alembic/: env.py reads MYSQL_* env vars; 0001_initial_schema mirrors db.sql - alembic.ini: script_location configured, URL injected at runtime Since db.sql already created the tables, stamp the DB before running future migrations: alembic stamp head Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
41
app/models/print_job.py
Normal file
41
app/models/print_job.py
Normal file
@@ -0,0 +1,41 @@
|
||||
import enum
|
||||
from datetime import datetime
|
||||
from decimal import Decimal
|
||||
|
||||
from sqlalchemy import DateTime, Enum, ForeignKey, Integer, Numeric, String, Text, func
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from app.models.base import Base
|
||||
|
||||
|
||||
class JobStatus(enum.Enum):
|
||||
queued = "queued"
|
||||
printing = "printing"
|
||||
done = "done"
|
||||
failed = "failed"
|
||||
cancelled = "cancelled"
|
||||
|
||||
|
||||
class PrintJob(Base):
|
||||
__tablename__ = "print_jobs"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
printer_id: Mapped[int] = mapped_column(ForeignKey("printers.id"))
|
||||
filament_id: Mapped[int | None] = mapped_column(ForeignKey("filaments.id"))
|
||||
name: Mapped[str] = mapped_column(String(200))
|
||||
file_name: Mapped[str | None] = mapped_column(String(255))
|
||||
status: Mapped[JobStatus] = mapped_column(Enum(JobStatus), default=JobStatus.queued)
|
||||
queue_position: Mapped[int | None] = mapped_column(Integer)
|
||||
started_at: Mapped[datetime | None] = mapped_column(DateTime)
|
||||
finished_at: Mapped[datetime | None] = mapped_column(DateTime)
|
||||
duration_minutes: Mapped[int | None] = mapped_column(Integer)
|
||||
filament_used_g: Mapped[Decimal | None] = mapped_column(Numeric(8, 2))
|
||||
cost_eur: Mapped[Decimal | None] = mapped_column(Numeric(8, 2))
|
||||
notes: Mapped[str | None] = mapped_column(Text)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now())
|
||||
updated_at: Mapped[datetime] = mapped_column(
|
||||
DateTime, server_default=func.now(), onupdate=func.now()
|
||||
)
|
||||
|
||||
printer: Mapped["Printer"] = relationship(back_populates="jobs")
|
||||
filament: Mapped["Filament | None"] = relationship(back_populates="jobs")
|
||||
Reference in New Issue
Block a user