hard · ~12 min
The billing system logs plan change events showing when each customer moved to a plan. Downstream reporting needs a validity-interval table with one row per plan stint showing when each plan took effect and when it ended.
plan_changes
effective_from
changed_at
effective_to
NULL
customer_id
plan
Input contract: (customer_id, changed_at) is unique and non-null in plan_changes (no two changes for the same customer share a timestamp); plan is non-null; consecutive events for a customer always represent a plan change.
(customer_id, changed_at)