Skip to main content

Week plan

week_plans and week_plan_items tables (migrations 000044 + 000048).
3 min read

Ephemeral per-week planning (Monday) and items per day. Migrations: 000044_week_plan, 000048_week_plan_intent_links, 000051_week_plan_series.

Conventions: soft delete, date_key / week_start_date_key as TEXT YYYY-MM-DD (Conventions). Week: Monday (weekStartsOn: 1).

Product: Week plan. Distinct from nutrition_meal_plans / slots.

week_plans#

Week header per profile.

ColumnNotes
idUUID PK
profile_idFK → profiles
week_start_date_keyMonday YYYY-MM-DD
intentTEXT nullable — short weekly intent
created_byFK → users
created_at / updated_atTIMESTAMPTZ
deleted_atSoft delete

Indexes#

IndexDefinition
idx_week_plans_profile_week_activeUNIQUE (profile_id, week_start_date_key) WHERE deleted_at IS NULL

week_plan_items#

Plan items (one day of the week).

ColumnNotes
idUUID PK
plan_idFK → week_plans
profile_idFK → profiles (denormalized for scope)
date_keyLocal day YYYY-MM-DD. NULL = Later (no day, scoped to that week)
titleTEXT NOT NULL
notesTEXT nullable (short)
done_atTIMESTAMPTZ nullable
sort_orderINT NOT NULL DEFAULT 0
calendar_reminder_idUUID nullable FK → reminders (ON DELETE SET NULL)
source_task_idUUID nullable FK → tasks (ON DELETE SET NULL)
source_activity_idUUID nullable FK → activities (ON DELETE SET NULL); XOR with task
series_idUUID nullable FK → week_plan_series (ON DELETE SET NULL)
created_byFK → users
created_at / updated_atTIMESTAMPTZ
deleted_atSoft delete

No time of their own, assignees, or plan limits. Time lives on the linked reminder. Weekly recurrence lives in week_plan_series.

Indexes#

IndexDefinition
idx_week_plan_items_plan_date_sort(plan_id, date_key, sort_order) WHERE deleted_at IS NULL
idx_week_plan_items_profile(profile_id) WHERE deleted_at IS NULL
idx_week_plan_items_calendar_reminder(calendar_reminder_id) WHERE … IS NOT NULL AND deleted_at IS NULL
idx_week_plan_items_source_task(source_task_id) WHERE … IS NOT NULL AND deleted_at IS NULL
idx_week_plan_items_source_activity(source_activity_id) WHERE … IS NOT NULL AND deleted_at IS NULL
idx_week_plan_items_series_dateUNIQUE (series_id, date_key) WHERE series_id IS NOT NULL (includes soft-deleted)
idx_week_plan_items_series(series_id) WHERE … IS NOT NULL AND deleted_at IS NULL

week_plan_series#

Weekly template: one item per weekday (0 = Sunday … 6 = Saturday, same as Activities).

ColumnNotes
title / notesSnapshot when the series is created; editing an occurrence does not change it
weekdaySMALLINT 0–6
starts_on_week_start_date_keyMonday YYYY-MM-DD of the week Repeat was turned on. Does not materialize earlier weeks
source_activity_idHabit inherited by materialized occurrences
soft deletedeleted_at pauses the series (does not materialize future weeks)

Indexes#

IndexDefinition
idx_week_plan_series_profile(profile_id) WHERE deleted_at IS NULL

Lifecycle#

  • GET by-week does not insert a header; lazy creation happens on POST of the first item or PATCH of intent.
  • POST /series/ensure materializes occurrences of active series in that week if weekStartDateKey >= starts_on_week_start_date_key (may create header + items). A soft-deleted occurrence is not recreated.
  • A non-null date_key is projected into Calendar automatically. calendar_reminder_id is only optional time/email metadata; it does not control visibility.
  • Item delete = soft-delete (deleted_at). The product flow deletes any linked reminder and clears calendar_reminder_id first, so restore returns a clean dated item.
  • Moving an item to Later clears date_key, deletes any linked reminder, and clears calendar_reminder_id. If the item belongs to an active weekly series, the series is paused (deleted_at).
  • Moving a repeating item to another day updates week_plan_series.weekday. Already-materialized weeks are not rewritten. POST /series/ensure skips a week that already has any occurrence of that series (including a soft-deleted one).
  • Who writes: Go domain internal/weekplan + Next services services/weekplan.