Add duration_minutes field to schedule blocks

Separates "recommended time" (time_start/time_end) from actual timer
duration. If duration_minutes is set, the timer counts down from that
value; otherwise falls back to the time_start–time_end window.

- ScheduleBlock model: add nullable duration_minutes INT column
- Startup migration: idempotent ADD COLUMN for existing DBs
- Schemas: duration_minutes in create, update, and out
- TimerDisplay: prefer duration_minutes * 60 over time diff when set
- Admin block forms: Duration (min) input on add and edit forms

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-28 10:23:30 -08:00
parent a019e2dda5
commit 1939b2cc45
5 changed files with 21 additions and 2 deletions

View File

@@ -31,6 +31,7 @@ async def lifespan(app: FastAPI):
# Idempotent column additions for schema migrations
await _add_column_if_missing(conn, "schedule_templates", "day_start_time", "TIME NULL")
await _add_column_if_missing(conn, "schedule_templates", "day_end_time", "TIME NULL")
await _add_column_if_missing(conn, "schedule_blocks", "duration_minutes", "INT NULL")
yield

View File

@@ -39,6 +39,7 @@ class ScheduleBlock(Base):
)
time_start: Mapped[time] = mapped_column(Time, nullable=False)
time_end: Mapped[time] = mapped_column(Time, nullable=False)
duration_minutes: Mapped[int | None] = mapped_column(Integer, nullable=True)
label: Mapped[str | None] = mapped_column(String(100), nullable=True) # override subject name
notes: Mapped[str | None] = mapped_column(Text, nullable=True)
order_index: Mapped[int] = mapped_column(Integer, default=0)

View File

@@ -6,6 +6,7 @@ class ScheduleBlockCreate(BaseModel):
subject_id: int | None = None
time_start: time
time_end: time
duration_minutes: int | None = None
label: str | None = None
notes: str | None = None
order_index: int = 0
@@ -15,6 +16,7 @@ class ScheduleBlockUpdate(BaseModel):
subject_id: int | None = None
time_start: time | None = None
time_end: time | None = None
duration_minutes: int | None = None
label: str | None = None
notes: str | None = None
order_index: int | None = None
@@ -25,6 +27,7 @@ class ScheduleBlockOut(BaseModel):
subject_id: int | None
time_start: time
time_end: time
duration_minutes: int | None
label: str | None
notes: str | None
order_index: int