Files
paliad/internal/db/migrations/075_project_events_timeline_kind.up.sql
m 49c260b888 feat(t-paliad-171): migration 075 — project_events.timeline_kind opt-in column
Adds a nullable text column on paliad.project_events so a subset of
audit rows can opt into surfacing as SmartTimeline content. Existing
rows stay NULL (audit-only); the partial index keeps the lookup tiny
because the SmartTimeline read filter is the indexed predicate.

Value space (enforced in code in internal/services/projection_service.go):
  'milestone'        — structural event (counterclaim_filed, ...)
  'custom_milestone' — free-text "Eigener Meilenstein"
  NULL               — audit only (default)

Design ref: docs/design-smart-timeline-2026-05-08.md §2.2.
2026-05-08 23:33:53 +02:00

33 lines
1.6 KiB
SQL

-- t-paliad-171 — SmartTimeline Slice 1.
-- Add the `timeline_kind` opt-in column to paliad.project_events so a
-- subset of audit rows can surface as timeline content. Existing rows
-- stay NULL (audit-only) and are filtered out of the SmartTimeline
-- read path; new write paths (custom milestone, counterclaim_created
-- in later slices) set the column on insert.
--
-- Value space (enforced in code, not via CHECK — see
-- internal/services/projection_service.go):
-- 'milestone' — structural event worth pinning to the timeline
-- (counterclaim_filed, third_party_intervened,
-- party_amendment, our_side_changed, scope_change)
-- 'custom_milestone' — free-text user-added event ("Eigener Meilenstein")
-- NULL — audit only (default, all existing rows)
--
-- Design ref: docs/design-smart-timeline-2026-05-08.md §2.2.
ALTER TABLE paliad.project_events
ADD COLUMN IF NOT EXISTS timeline_kind text NULL;
COMMENT ON COLUMN paliad.project_events.timeline_kind IS
'When non-NULL, this audit event also surfaces as a SmartTimeline '
'milestone. NULL keeps the row audit-only. See '
'internal/services/projection_service.go for the value space.';
-- Partial index — the SmartTimeline read path filters on
-- (project_id, timeline_kind IS NOT NULL); making the index partial
-- keeps it tiny (most rows stay audit-only) while still serving the
-- common lookup.
CREATE INDEX IF NOT EXISTS project_events_timeline_kind_idx
ON paliad.project_events (project_id, timeline_kind)
WHERE timeline_kind IS NOT NULL;