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:
33
app/models/printer.py
Normal file
33
app/models/printer.py
Normal file
@@ -0,0 +1,33 @@
|
||||
import enum
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import DateTime, Enum, String, func
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from app.models.base import Base
|
||||
|
||||
|
||||
class PrinterStatus(enum.Enum):
|
||||
idle = "idle"
|
||||
printing = "printing"
|
||||
error = "error"
|
||||
offline = "offline"
|
||||
|
||||
|
||||
class Printer(Base):
|
||||
__tablename__ = "printers"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
name: Mapped[str] = mapped_column(String(100))
|
||||
model: Mapped[str | None] = mapped_column(String(100))
|
||||
location: Mapped[str | None] = mapped_column(String(100))
|
||||
status: Mapped[PrinterStatus] = mapped_column(
|
||||
Enum(PrinterStatus), default=PrinterStatus.offline
|
||||
)
|
||||
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()
|
||||
)
|
||||
|
||||
jobs: Mapped[list["PrintJob"]] = relationship(back_populates="printer")
|
||||
todos: Mapped[list["Todo"]] = relationship(back_populates="printer")
|
||||
Reference in New Issue
Block a user