pub async fn transition(
conn: &mut PgConnection,
id: Uuid,
transition: &Transition,
) -> ModelResult<CreditRegistration>Expand description
Moves a ledger row to a new state and appends the matching audit event, atomically.
The only writer of state, and the one place (from → to) legality is decided: an edge outside
the transition’s TransitionPolicy is refused as InvalidRequest rather than written. A row
no longer in expected_from_state is refused as PreconditionFailed; a caller that has to tell
that apart from a real failure uses transition_unless_moved_on instead.
Owns the lifecycle stamps, so callers must not touch them (bar
reset_for_resubmission clearing first_failed_at):
state_entered_at, state_changed_at, phase_started_at, terminal_at, first_failed_at,
submit_retry_count, registered_at, submitted_at, enrolment_checked_at,
enrolment_banner_dismissed_at, no_usable_enrolment_since and next_attempt_at, which takes
the target state’s default cadence unless the caller names a time. Starting to wait for an
enrolment clears first_failed_at, submit_retry_count and enrolment_banner_dismissed_at;
leaving that wait clears the check schedule, but not enrolment_check_group. Every move clears
the claim of an enrolment check. Returns the row as written.