Add printer lifecycle fields and printer log
- Printer: bought_at, last_maintenance_at, decommissioned_at (all Date, nullable)
- PrinterLog: per-printer timestamped text entries (CASCADE delete)
- Migration 0003: adds columns + printer_logs table
- /printers/{id}: detail page showing lifecycle info + scrollable log
- POST /printers/{id}/log: add a log entry via modal form
- Printer names in list are now links to the detail page
- Add Printer modal includes optional purchase date
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
39
alembic/versions/0003_printer_lifecycle_and_logs.py
Normal file
39
alembic/versions/0003_printer_lifecycle_and_logs.py
Normal file
@@ -0,0 +1,39 @@
|
||||
"""printer lifecycle fields and printer_logs table
|
||||
|
||||
Revision ID: 0003
|
||||
Revises: 0002
|
||||
Create Date: 2026-06-18
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
revision: str = "0003"
|
||||
down_revision: Union[str, None] = "0002"
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.add_column("printers", sa.Column("bought_at", sa.Date(), nullable=True))
|
||||
op.add_column("printers", sa.Column("last_maintenance_at", sa.Date(), nullable=True))
|
||||
op.add_column("printers", sa.Column("decommissioned_at", sa.Date(), nullable=True))
|
||||
|
||||
op.create_table(
|
||||
"printer_logs",
|
||||
sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
|
||||
sa.Column("printer_id", sa.Integer(), nullable=False),
|
||||
sa.Column("message", sa.Text(), nullable=False),
|
||||
sa.Column("created_at", sa.DateTime(), nullable=False, server_default=sa.text("CURRENT_TIMESTAMP")),
|
||||
sa.ForeignKeyConstraint(["printer_id"], ["printers.id"], name="fk_log_printer", ondelete="CASCADE"),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_table("printer_logs")
|
||||
op.drop_column("printers", "decommissioned_at")
|
||||
op.drop_column("printers", "last_maintenance_at")
|
||||
op.drop_column("printers", "bought_at")
|
||||
Reference in New Issue
Block a user