Files
HealthLog/prisma/migrations/0495_cycle_feed_forecast_style/migration.sql
T
Marc-André Bombeck 546b9b2569 feat(cycle): choose how the calendar feed draws a forecast (#1350)
A forecast period was one all-day event over every day it might fall on,
so a period of a few days showed up as a week-long estimate next to the
logged ones. Each feed now carries a forecast style:

- EXACT: the calculated period only, from the most likely start for the
  predicted number of bleeding days.
- MARGIN: that event, plus separate "possible" events for the days it may
  start earlier and the days it may still run on, each only where the
  band reaches that side. Discreet titles use an open dot for them.
- BAND: the single range, unchanged.

Migration 0495 adds the column with BAND as its default, so every live
feed keeps the events it serves. A feed turned on from now on starts on
MARGIN, set by the mint route. PATCH changes it, rotate copies it, the
status and the audit diff carry it, and the settings card offers it with
a one-line explanation of the chosen style. The horizon and its stop rule
are the same in every style, and the period event keeps its UID across
styles so a calendar updates it in place.
2026-11-09 10:59:18 +01:00

34 lines
1.3 KiB
SQL

-- How the cycle calendar feed draws a forecast period (#1350):
--
-- EXACT the calculated period only, no margin
-- MARGIN the calculated period, plus the days it may start earlier or end
-- later as separate "possible" events
-- BAND one event covering every day the period may fall on
--
-- The column defaults to BAND, which is what every feed drew until now, so an
-- existing subscription keeps exactly the events it had. A new subscription is
-- given MARGIN by the route that mints it, not by this default.
--
-- One DO block, so the file is one statement that rolls back whole and the
-- lock wait on `cycle_calendar_feeds` is bounded. The type is created only when
-- missing and the column only when missing, so a replay is harmless.
-- Reversibility: dropping the column and the type returns every feed to the
-- single-band forecast.
--
-- @retry-on-lock-timeout
DO $migration$
BEGIN
PERFORM set_config('lock_timeout', '5s', true);
IF NOT EXISTS (
SELECT 1 FROM pg_type WHERE typname = 'cycle_calendar_feed_forecast_style'
) THEN
CREATE TYPE "cycle_calendar_feed_forecast_style" AS ENUM ('EXACT', 'MARGIN', 'BAND');
END IF;
ALTER TABLE "cycle_calendar_feeds"
ADD COLUMN IF NOT EXISTS "forecast_style" "cycle_calendar_feed_forecast_style" NOT NULL DEFAULT 'BAND';
END
$migration$;