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:
2026-09-19 15:53:25 +02:00
parent c6593062e3
commit 6d92b87bf3
43 changed files with 2735 additions and 638 deletions
@@ -1,7 +1,10 @@
"""SQLite implementation of LeaveWishRepository.
Handles the leave_wish table. The recurring window is stored as month/day
integers (not dates) so it can repeat yearly (see app/entities/leave_wish.py).
Handles the leave_wish table. One row is ONE year's occurrence: a repeating
wish is materialised by `LeaveWishService` into one row per year, grouped by
`series_id` (see app/entities/leave_wish.py). The window is stored as month/day
integers anchored at `first_year` rather than as two dates -- the existing
column layout, which keeps the wrap rule expressible without a custom type.
"""
from datetime import datetime
@@ -34,7 +37,6 @@ class SQLiteLeaveWishRepository(LeaveWishRepository):
window_end_day=row["window_end_day"],
target_weeks=row["target_weeks"],
target_days=row["target_days"],
recurrence=row["recurrence"],
first_year=row["first_year"],
last_year=row["last_year"],
priority=row["priority"],
@@ -45,6 +47,7 @@ class SQLiteLeaveWishRepository(LeaveWishRepository):
else None
),
window_mode=row["window_mode"],
series_id=UUID(row["series_id"]) if row["series_id"] is not None else None,
wants_dubbeldag=bool(row["wants_dubbeldag"]),
created_at=datetime.fromisoformat(row["created_at"]),
updated_at=datetime.fromisoformat(row["updated_at"]),
@@ -59,9 +62,9 @@ class SQLiteLeaveWishRepository(LeaveWishRepository):
INSERT INTO leave_wish
(id, workspace_id, child_id, name, name_message_key,
window_start_month, window_start_day, window_end_month, window_end_day,
target_weeks, target_days, recurrence, first_year, last_year,
target_weeks, target_days, first_year, last_year,
priority, parent_mode, parent_personal_data_uuid,
window_mode, wants_dubbeldag, created_at, updated_at)
window_mode, series_id, wants_dubbeldag, created_at, updated_at)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
""",
(
@@ -76,7 +79,6 @@ class SQLiteLeaveWishRepository(LeaveWishRepository):
item.window_end_day,
item.target_weeks,
item.target_days,
item.recurrence,
item.first_year,
item.last_year,
item.priority,
@@ -87,6 +89,7 @@ class SQLiteLeaveWishRepository(LeaveWishRepository):
else None
),
item.window_mode,
str(item.series_id) if item.series_id is not None else None,
int(item.wants_dubbeldag),
item.created_at.isoformat(),
item.updated_at.isoformat(),
@@ -109,6 +112,14 @@ class SQLiteLeaveWishRepository(LeaveWishRepository):
rows = await cursor.fetchall()
return [self._row_to_entity(row) for row in rows]
async def get_by_series(self, series_id: UUID) -> list[LeaveWish]:
cursor = await self._conn.execute(
"SELECT * FROM leave_wish WHERE series_id = ? ORDER BY first_year ASC",
(str(series_id),),
)
rows = await cursor.fetchall()
return [self._row_to_entity(row) for row in rows]
async def update(self, id: UUID, item: LeaveWish) -> LeaveWish:
item.updated_at = datetime.now()
cursor = await self._conn.execute(
@@ -117,9 +128,9 @@ class SQLiteLeaveWishRepository(LeaveWishRepository):
SET child_id = ?, name = ?, name_message_key = ?,
window_start_month = ?, window_start_day = ?,
window_end_month = ?, window_end_day = ?,
target_weeks = ?, target_days = ?, recurrence = ?, first_year = ?, last_year = ?,
target_weeks = ?, target_days = ?, first_year = ?, last_year = ?,
priority = ?, parent_mode = ?, parent_personal_data_uuid = ?,
window_mode = ?, wants_dubbeldag = ?, updated_at = ?
window_mode = ?, series_id = ?, wants_dubbeldag = ?, updated_at = ?
WHERE id = ?
""",
(
@@ -132,7 +143,6 @@ class SQLiteLeaveWishRepository(LeaveWishRepository):
item.window_end_day,
item.target_weeks,
item.target_days,
item.recurrence,
item.first_year,
item.last_year,
item.priority,
@@ -143,6 +153,7 @@ class SQLiteLeaveWishRepository(LeaveWishRepository):
else None
),
item.window_mode,
str(item.series_id) if item.series_id is not None else None,
int(item.wants_dubbeldag),
item.updated_at.isoformat(),
str(id),