Give every year of a repeating period its own row
A repeating period was a single row that the planner expanded into one window per year at read time, so no year had anywhere to differ from the others. Editing one year rewrote them all, and removing a year in the middle had to split the wish in two. Neither survives contact with the thing this app is for: Easter moves, and the cheapest week is not the same week every year. Each year is now its own row, linked by a series id. Editing one year touches one row; editing the series re-projects the rest from it. Removing a year is one delete. The weekday snap is worked out once, when the rows are made, and stored, so a row now says what it means rather than being re-derived on every read. Recurrence stops being a stored field and becomes what it always was in practice — an instruction at create and update time; whether a period repeats is whether it belongs to a series. Migration 004 rebuilds the table and expands the existing rows, keeping each original row as its first year so the days already planned against it still point somewhere. A Feb 29 anchor recurring into a common year used to raise out of the allocator; it clamps now. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ei7gCZzdd751uZtPzb1Pep
This commit is contained in:
@@ -33,8 +33,15 @@ class LeaveWishCreate(BaseModel):
|
||||
# A calendar-drawn period is not a whole number of weeks. None (default)
|
||||
# falls back to `target_weeks * 7` — see `LeaveWish.target_span_days()`.
|
||||
target_days: int | None = Field(default=None, ge=1)
|
||||
# An INSTRUCTION, not a stored field (see app/services/leave_wish_service.py):
|
||||
# 'yearly' materialises one row per year, all sharing a `series_id`, from
|
||||
# `first_year` through `last_year` (or, when that is None, the child's 4th
|
||||
# birthday year). 'once' creates a single standalone occurrence. What comes
|
||||
# back is always one occurrence — the `first_year` one.
|
||||
recurrence: str = "once" # 'yearly' | 'once'
|
||||
first_year: int = Field(ge=2000, le=2200)
|
||||
# Series-level end-year intent; None = "until the child turns 4". Ignored
|
||||
# (normalised to None) when `recurrence == 'once'`.
|
||||
last_year: int | None = Field(default=None, ge=2000, le=2200)
|
||||
|
||||
priority: int = Field(default=1, ge=1)
|
||||
@@ -46,6 +53,14 @@ class LeaveWishCreate(BaseModel):
|
||||
# bounding range the allocator searches within for the best-costing window.
|
||||
window_mode: str = "fixed" # 'fixed' | 'flexible'
|
||||
|
||||
# Re-attach this one occurrence to an EXISTING series (the series must
|
||||
# already have at least one row in the same workspace). Only valid with
|
||||
# `recurrence == 'once'` — a 'yearly' create mints its own series id. This
|
||||
# exists so the calendar's undo can put back a single year it removed as
|
||||
# the same year of the same repeating wish, rather than as a detached
|
||||
# one-off that a later "every year" edit would miss.
|
||||
series_id: UUID | None = None
|
||||
|
||||
# §Decision A (co-leave) — opt-in dubbeldagar; see app/entities/leave_wish.py.
|
||||
# Only meaningful when parent_mode == 'both'.
|
||||
wants_dubbeldag: bool = False
|
||||
@@ -72,8 +87,15 @@ class LeaveWishUpdate(BaseModel):
|
||||
# means "leave unchanged" — same convention as the other nullable fields
|
||||
# on this model (see `_clear_*` handling in `LeaveWishService.update`).
|
||||
target_days: int | None = Field(default=None, ge=1)
|
||||
# Same instruction as on `LeaveWishCreate`, applied to an existing row:
|
||||
# 'yearly' on a standalone occurrence materialises a series around it;
|
||||
# 'once' on a series occurrence keeps this row and deletes its siblings.
|
||||
# Absent means "leave the row's repeat-ness alone".
|
||||
recurrence: str | None = None
|
||||
first_year: int | None = Field(None, ge=2000, le=2200)
|
||||
# Series-level; changing it on a row that is already part of a series
|
||||
# requires `?scope=series` (the service rejects it otherwise), since it
|
||||
# extends or shortens every year at once.
|
||||
last_year: int | None = Field(None, ge=2000, le=2200)
|
||||
|
||||
priority: int | None = Field(None, ge=1)
|
||||
@@ -102,8 +124,10 @@ class LeaveWishResponse(BaseModel):
|
||||
|
||||
target_weeks: int
|
||||
target_days: int | None
|
||||
recurrence: str
|
||||
first_year: int
|
||||
# Series-level intent, mirrored on every row of a series; None on a
|
||||
# standalone occurrence (and on a series that runs "until the child
|
||||
# turns 4"). See app/entities/leave_wish.py.
|
||||
last_year: int | None
|
||||
|
||||
priority: int
|
||||
@@ -112,6 +136,11 @@ class LeaveWishResponse(BaseModel):
|
||||
|
||||
window_mode: str
|
||||
|
||||
# Non-null when this occurrence is one year of a repeating wish; every
|
||||
# year of that wish shares the value. This replaces the old `recurrence`
|
||||
# field: "does this repeat?" is now "does it belong to a series?".
|
||||
series_id: UUID | None
|
||||
|
||||
wants_dubbeldag: bool
|
||||
|
||||
created_at: datetime | None
|
||||
@@ -131,13 +160,13 @@ class LeaveWishResponse(BaseModel):
|
||||
window_end_day=entity.window_end_day,
|
||||
target_weeks=entity.target_weeks,
|
||||
target_days=entity.target_days,
|
||||
recurrence=entity.recurrence,
|
||||
first_year=entity.first_year,
|
||||
last_year=entity.last_year,
|
||||
priority=entity.priority,
|
||||
parent_mode=entity.parent_mode,
|
||||
parent_personal_data_uuid=entity.parent_personal_data_uuid,
|
||||
window_mode=entity.window_mode,
|
||||
series_id=entity.series_id,
|
||||
wants_dubbeldag=entity.wants_dubbeldag,
|
||||
created_at=entity.created_at,
|
||||
updated_at=entity.updated_at,
|
||||
|
||||
Reference in New Issue
Block a user