Make printer optional on job creation — assigned when job starts
Migration 0005 makes print_jobs.printer_id nullable. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
28
alembic/versions/0005_nullable_printer_id.py
Normal file
28
alembic/versions/0005_nullable_printer_id.py
Normal file
@@ -0,0 +1,28 @@
|
||||
"""make print_jobs.printer_id nullable — printer is assigned at job start
|
||||
|
||||
Revision ID: 0005
|
||||
Revises: 0004
|
||||
Create Date: 2026-06-18
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
revision: str = "0005"
|
||||
down_revision: Union[str, None] = "0004"
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.alter_column("print_jobs", "printer_id",
|
||||
existing_type=sa.Integer(),
|
||||
nullable=True)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.alter_column("print_jobs", "printer_id",
|
||||
existing_type=sa.Integer(),
|
||||
nullable=False)
|
||||
@@ -22,7 +22,7 @@ class PrintJob(Base):
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
job_uuid: Mapped[str | None] = mapped_column(String(36), unique=True, default=lambda: str(_uuid.uuid4()))
|
||||
printer_id: Mapped[int] = mapped_column(ForeignKey("printers.id"))
|
||||
printer_id: Mapped[int | None] = mapped_column(ForeignKey("printers.id"))
|
||||
filament_id: Mapped[int | None] = mapped_column(ForeignKey("filaments.id"))
|
||||
name: Mapped[str] = mapped_column(String(200))
|
||||
customer: Mapped[str | None] = mapped_column(String(200))
|
||||
|
||||
@@ -141,7 +141,7 @@ def jobs_page(request: Request, q: str = "", db: Session = Depends(get_db)):
|
||||
|
||||
@router.post("/jobs")
|
||||
async def create_job(
|
||||
printer_id: int = Form(...),
|
||||
printer_id: str = Form(""),
|
||||
customer: str = Form(""),
|
||||
filament_id: str = Form(""),
|
||||
notes: str = Form(""),
|
||||
@@ -160,7 +160,7 @@ async def create_job(
|
||||
job_uuid=str(_uuid.uuid4()),
|
||||
name=Path(filename).stem if filename else (customer.strip() or "Unnamed"),
|
||||
file_name=filename,
|
||||
printer_id=printer_id,
|
||||
printer_id=int(printer_id) if printer_id else None,
|
||||
filament_id=int(filament_id) if filament_id else None,
|
||||
customer=customer.strip() or None,
|
||||
notes=notes.strip() or None,
|
||||
|
||||
@@ -85,9 +85,9 @@
|
||||
|
||||
<div class="row g-3">
|
||||
<div class="col-md-6">
|
||||
<label class="form-label text-secondary small">Printer <span class="text-danger">*</span></label>
|
||||
<select name="printer_id" class="form-select bg-dark border-secondary text-white" required>
|
||||
<option value="">— select —</option>
|
||||
<label class="form-label text-secondary small">Printer <span class="text-secondary fw-normal">(assigned when starting)</span></label>
|
||||
<select name="printer_id" class="form-select bg-dark border-secondary text-white">
|
||||
<option value="">— unassigned —</option>
|
||||
{% for p in printers %}
|
||||
<option value="{{ p.id }}">{{ p.name }}{% if p.location %} ({{ p.location }}){% endif %}</option>
|
||||
{% endfor %}
|
||||
|
||||
Reference in New Issue
Block a user