- 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>
39 lines
1.2 KiB
Python
39 lines
1.2 KiB
Python
import enum
|
|
from datetime import datetime
|
|
from decimal import Decimal
|
|
|
|
from sqlalchemy import DateTime, Enum, Numeric, String, func
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from app.models.base import Base
|
|
|
|
|
|
class Material(enum.Enum):
|
|
PLA = "PLA"
|
|
PETG = "PETG"
|
|
ABS = "ABS"
|
|
ASA = "ASA"
|
|
TPU = "TPU"
|
|
Nylon = "Nylon"
|
|
PC = "PC"
|
|
Other = "Other"
|
|
|
|
|
|
class Filament(Base):
|
|
__tablename__ = "filaments"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True)
|
|
brand: Mapped[str | None] = mapped_column(String(100))
|
|
material: Mapped[Material] = mapped_column(Enum(Material), default=Material.PLA)
|
|
color: Mapped[str | None] = mapped_column(String(100))
|
|
color_hex: Mapped[str | None] = mapped_column(String(7))
|
|
weight_total_g: Mapped[Decimal] = mapped_column(Numeric(8, 2))
|
|
weight_remaining_g: Mapped[Decimal] = mapped_column(Numeric(8, 2))
|
|
price_per_kg_eur: Mapped[Decimal | None] = mapped_column(Numeric(8, 2))
|
|
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="filament")
|